diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-04-05 18:00:28 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-04-05 18:00:28 -0400 |
commit | 729cb49f52c825ac44f437e1ff0865d9f0b3626a (patch) | |
tree | 18db05e36f16fcdfc1147f4ba1ea19a0ee4bea9c /src/thread/pthread_create.c | |
parent | 918a40f257328a2d7490829b54687cd38d7b787b (diff) | |
download | musl-729cb49f52c825ac44f437e1ff0865d9f0b3626a.tar.gz musl-729cb49f52c825ac44f437e1ff0865d9f0b3626a.tar.xz musl-729cb49f52c825ac44f437e1ff0865d9f0b3626a.zip |
new framework to inhibit thread cancellation when needed
with these small changes, libc functions which need to call functions which are cancellation points, but which themselves must not be cancellation points, can use the CANCELPT_INHIBIT and CANCELPT_RESUME macros to temporarily inhibit all cancellation.
Diffstat (limited to 'src/thread/pthread_create.c')
-rw-r--r-- | src/thread/pthread_create.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 284b45a0..52487001 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -57,9 +57,19 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx) static void cancelpt(int x) { struct pthread *self = __pthread_self(); - if (self->canceldisable) return; - if ((self->cancelpoint+=x)==1 && x>=0 && self->cancel) - docancel(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; + } } /* "rsyscall" is a mechanism by which a thread can synchronously force all |