From b22d701bb72b928526efff83c019b912f469af72 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 5 Apr 2003 05:21:15 +0000 Subject: Update. 2003-04-04 Ulrich Drepper * sysdeps/pthread/createthread.c (create_thread): Add some more comments explaining when to set multiple_threads and when not. * pthreadP.h: Define THREAD_ATOMIC_CMPXCHG_VAL and THREAD_ATOMIC_BIT_SET if not already defined. * sysdeps/i386/tls.h: Define THREAD_ATOMIC_CMPXCHG_VAL and THREAD_ATOMIC_BIT_SET: * sysdeps/x86_64/tls.h: Likewise. * cleanup_defer.c (_pthread_cleanup_push_defer): Rewrite to use THREAD_ATOMIC_CMPXCHG_VAL. (_pthread_cleanup_pop_restore): Likewise. * cancellation.c (__pthread_enable_asynccancel): Likewise. (__pthread_enable_asynccancel_2): Likewise. (__pthread_disable_asynccancel): Likewise. * libc-cancellation.c (__libc_enable_asynccancel): Likewise. (__libc_disable_asynccancel): Likewise. * init.c (sigcancel_handler): Likewise. * pthread_setcancelstate.c (__pthread_setcancelstate): Likewise. * pthread_setcanceltype.c (__pthread_setcanceltype): Likewise. --- nptl/cleanup_defer.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'nptl/cleanup_defer.c') diff --git a/nptl/cleanup_defer.c b/nptl/cleanup_defer.c index 5d6ed03..7945a0d 100644 --- a/nptl/cleanup_defer.c +++ b/nptl/cleanup_defer.c @@ -18,7 +18,6 @@ 02111-1307 USA. */ #include "pthreadP.h" -#include void @@ -37,13 +36,19 @@ _pthread_cleanup_push_defer (buffer, routine, arg) /* Disable asynchronous cancellation for now. */ if (__builtin_expect (cancelhandling & CANCELTYPE_BITMASK, 0)) - { - while (atomic_compare_and_exchange_bool_acq (&self->cancelhandling, - cancelhandling - & ~CANCELTYPE_BITMASK, - cancelhandling)) - cancelhandling = self->cancelhandling; - } + while (1) + { + int newval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, + cancelhandling + & ~CANCELTYPE_BITMASK, + cancelhandling); + if (__builtin_expect (newval == cancelhandling, 1)) + /* Successfully replaced the value. */ + break; + + /* Prepare for the next round. */ + cancelhandling = newval; + } buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK ? PTHREAD_CANCEL_ASYNCHRONOUS @@ -53,6 +58,7 @@ _pthread_cleanup_push_defer (buffer, routine, arg) } strong_alias (_pthread_cleanup_push_defer, __pthread_cleanup_push_defer) + void _pthread_cleanup_pop_restore (buffer, execute) struct _pthread_cleanup_buffer *buffer; @@ -67,11 +73,19 @@ _pthread_cleanup_pop_restore (buffer, execute) && ((cancelhandling = THREAD_GETMEM (self, cancelhandling)) & CANCELTYPE_BITMASK) == 0) { - while (atomic_compare_and_exchange_bool_acq (&self->cancelhandling, - cancelhandling - | CANCELTYPE_BITMASK, - cancelhandling)) - cancelhandling = self->cancelhandling; + while (1) + { + int newval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, + cancelhandling + | CANCELTYPE_BITMASK, + cancelhandling); + if (__builtin_expect (newval == cancelhandling, 1)) + /* Successfully replaced the value. */ + break; + + /* Prepare for the next round. */ + cancelhandling = newval; + } CANCELLATION_P (self); } -- cgit v1.1