X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fthread%2Fpthread_setcancelstate.c;h=ba2b231190436076b1d200bc76fa6e2c5dec9443;hp=a85cc800f7c64f8736133c2fad6ec6bff3ee791f;hb=97c5b5a87c3d9df54278e1073d6177f77536bd32;hpb=729cb49f52c825ac44f437e1ff0865d9f0b3626a diff --git a/src/thread/pthread_setcancelstate.c b/src/thread/pthread_setcancelstate.c index a85cc800..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 & 1; - if ((unsigned)new > 1) return EINVAL; - self->canceldisable = (self->canceldisable & ~1) | 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; }