X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fthread%2Fpthread_setcancelstate.c;h=ba2b231190436076b1d200bc76fa6e2c5dec9443;hp=23c38851a5910fe88aad2205dd35154d41708277;hb=e864ddc36819814b3b9ed17620459d66add512d3;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 diff --git a/src/thread/pthread_setcancelstate.c b/src/thread/pthread_setcancelstate.c index 23c38851..ba2b2311 100644 --- a/src/thread/pthread_setcancelstate.c +++ b/src/thread/pthread_setcancelstate.c @@ -2,9 +2,14 @@ int pthread_setcancelstate(int new, int *old) { - struct pthread *self = pthread_self(); - if (old) *old = self->canceldisable; - if ((unsigned)new > 1) return EINVAL; - self->canceldisable = new; + if (new > 1U) return EINVAL; + if (libc.main_thread) { + struct pthread *self = __pthread_self(); + if (old) *old = self->canceldisable; + self->canceldisable = new; + } else { + if (old) *old = libc.canceldisable; + libc.canceldisable = new; + } return 0; }