pthread_setcancelstate(3): make it async-signal-safe
(cherry picked from commit 030f48f78f96e0cdb30c960e1a11e5ae01d0eee8)