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/pthread_setcancelstate.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'nptl/pthread_setcancelstate.c') diff --git a/nptl/pthread_setcancelstate.c b/nptl/pthread_setcancelstate.c index a6af063d67..a452c2ec46 100644 --- a/nptl/pthread_setcancelstate.c +++ b/nptl/pthread_setcancelstate.c @@ -34,9 +34,9 @@ __pthread_setcancelstate (state, oldstate) self = THREAD_SELF; + int oldval = THREAD_GETMEM (self, cancelhandling); while (1) { - int oldval = THREAD_GETMEM (self, cancelhandling); int newval = (state == PTHREAD_CANCEL_DISABLE ? oldval | CANCELSTATE_BITMASK : oldval & ~CANCELSTATE_BITMASK); @@ -54,14 +54,18 @@ __pthread_setcancelstate (state, oldstate) /* Update the cancel handling word. This has to be done atomically since other bits could be modified as well. */ - if (! atomic_compare_and_exchange_bool_acq (&self->cancelhandling, - newval, oldval)) + int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval, + oldval); + if (__builtin_expect (curval == oldval, 1)) { if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval)) __do_cancel (); break; } + + /* Prepare for the next round. */ + oldval = curval; } return 0; -- cgit 1.4.1