diff options
Diffstat (limited to 'nptl/libc-cleanup.c')
-rw-r--r-- | nptl/libc-cleanup.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/nptl/libc-cleanup.c b/nptl/libc-cleanup.c index cb4c226281..c4a83591bf 100644 --- a/nptl/libc-cleanup.c +++ b/nptl/libc-cleanup.c @@ -26,9 +26,24 @@ __libc_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer) buffer->__prev = THREAD_GETMEM (self, cleanup); + int cancelhandling = atomic_load_relaxed (&self->cancelhandling); + /* Disable asynchronous cancellation for now. */ - buffer->__canceltype = THREAD_GETMEM (self, canceltype); - THREAD_SETMEM (self, canceltype, PTHREAD_CANCEL_DEFERRED); + if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK)) + { + int newval; + do + { + newval = cancelhandling & ~CANCELTYPE_BITMASK; + } + while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling, + &cancelhandling, + newval)); + } + + buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK + ? PTHREAD_CANCEL_ASYNCHRONOUS + : PTHREAD_CANCEL_DEFERRED); THREAD_SETMEM (self, cleanup, buffer); } @@ -41,8 +56,22 @@ __libc_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer) THREAD_SETMEM (self, cleanup, buffer->__prev); - THREAD_SETMEM (self, canceltype, buffer->__canceltype); - if (buffer->__canceltype == PTHREAD_CANCEL_ASYNCHRONOUS) - __pthread_testcancel (); + int cancelhandling = atomic_load_relaxed (&self->cancelhandling); + if (cancelhandling & CANCELTYPE_BITMASK) + { + int newval; + do + { + newval = cancelhandling | CANCELTYPE_BITMASK; + } + while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling, + &cancelhandling, newval)); + + if (cancel_enabled_and_canceled (cancelhandling)) + { + self->result = PTHREAD_CANCELED; + __do_cancel (); + } + } } libc_hidden_def (__libc_cleanup_pop_restore) |