@@ -33,19 +33,14 @@ ___pthread_register_cancel_defer (__pthread_unwind_buf_t *buf)
int cancelhandling = atomic_load_relaxed (&self->cancelhandling);
if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK))
{
- int newval;
- do
- {
- newval = cancelhandling & ~CANCELTYPE_BITMASK;
- }
- while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling,
- &cancelhandling,
- newval));
+ if (atomic_fetch_and_acquire (&self->cancelhandling, ~CANCELTYPE_BITMASK)
+ & CANCELTYPE_BITMASK)
+ ibuf->priv.data.canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+ else
+ ibuf->priv.data.canceltype = PTHREAD_CANCEL_DEFERRED;
}
-
- ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK
- ? PTHREAD_CANCEL_ASYNCHRONOUS
- : PTHREAD_CANCEL_DEFERRED);
+ else
+ ibuf->priv.data.canceltype = PTHREAD_CANCEL_DEFERRED;
/* Store the new cleanup handler info. */
THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
@@ -73,14 +68,7 @@ ___pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf)
int cancelhandling = atomic_load_relaxed (&self->cancelhandling);
if ((cancelhandling & CANCELTYPE_BITMASK) == 0)
{
- int newval;
- do
- {
- newval = cancelhandling | CANCELTYPE_BITMASK;
- }
- while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling,
- &cancelhandling, newval));
-
+ atomic_fetch_or_acquire (&self->cancelhandling, CANCELTYPE_BITMASK);
if (cancel_enabled_and_canceled (cancelhandling))
{
self->result = PTHREAD_CANCELED;
@@ -31,19 +31,14 @@ __libc_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer)
/* Disable asynchronous cancellation for now. */
if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK))
{
- int newval;
- do
- {
- newval = cancelhandling & ~CANCELTYPE_BITMASK;
- }
- while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling,
- &cancelhandling,
- newval));
+ if (atomic_fetch_and_acquire (&self->cancelhandling, ~CANCELTYPE_BITMASK)
+ & CANCELTYPE_BITMASK)
+ buffer->__canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+ else
+ buffer->__canceltype = PTHREAD_CANCEL_DEFERRED;
}
-
- buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK
- ? PTHREAD_CANCEL_ASYNCHRONOUS
- : PTHREAD_CANCEL_DEFERRED);
+ else
+ buffer->__canceltype = PTHREAD_CANCEL_DEFERRED;
THREAD_SETMEM (self, cleanup, buffer);
}
@@ -60,14 +55,7 @@ __libc_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer)
if (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED
&& (cancelhandling & CANCELTYPE_BITMASK) == 0)
{
- int newval;
- do
- {
- newval = cancelhandling | CANCELTYPE_BITMASK;
- }
- while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling,
- &cancelhandling, newval));
-
+ atomic_fetch_or_acquire (&self->cancelhandling, CANCELTYPE_BITMASK);
if (cancel_enabled_and_canceled (cancelhandling))
{
self->result = PTHREAD_CANCELED;