simplify cancellation point handling
authorRich Felker <dalias@aerifal.cx>
Thu, 14 Apr 2011 00:47:01 +0000 (20:47 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 14 Apr 2011 00:47:01 +0000 (20:47 -0400)
we take advantage of the fact that unless self->cancelpt is 1,
cancellation cannot happen. so just increment it by 2 to temporarily
block cancellation. this drops pthread_create.o well under 1k.

src/thread/pthread_create.c
src/thread/pthread_setcancelstate.c

index acbd5a41cdeb834c68a862266c1beb05dfa6679e..a782650420248683f9c94fc515edfd8e04a7e95a 100644 (file)
@@ -63,19 +63,8 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
 static void cancelpt(int x)
 {
        struct pthread *self = __pthread_self();
-       switch (x) {
-       case 1:
-               self->cancelpoint++;
-       case 0:
-               if (self->cancel && self->cancelpoint==1 && !self->canceldisable)
-                       docancel(self);
-               break;
-       case -1:
-               self->cancelpoint--;
-               break;
-       default:
-               self->canceldisable += x;
-       }
+       if ((self->cancelpoint+=x)==1 && self->cancel
+               && x<2U && !self->canceldisable) docancel(self);
 }
 
 static void init_threads()
index a85cc800f7c64f8736133c2fad6ec6bff3ee791f..aa0ddcdd316341ec0ab7a685e2e84a5a8a2b149b 100644 (file)
@@ -3,8 +3,8 @@
 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 (old) *old = self->canceldisable;
+       if (new > 1U) return EINVAL;
+       self->canceldisable = new;
        return 0;
 }