pthread_setcancelstate(3): make it async-signal-safe
by setting new cancel state and reading old cancel state from the
curthread structure atomic.
Note that this does not play well with async cancellation, since if
cancellation is enabled from a signal handler and cancellation request
is pending, the thread is cancelled immediately, calling user-defined
destructors, which all must be async-signal-safe (but this is a general
requirement for async cancellation anyway).
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D48200