about summary refs log tree commit diff
path: root/nptl/pthread_setcancelstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'nptl/pthread_setcancelstate.c')
-rw-r--r--nptl/pthread_setcancelstate.c10
1 files changed, 7 insertions, 3 deletions
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;