mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
Update.
2003-04-04 Ulrich Drepper <drepper@redhat.com> * 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.
This commit is contained in:
@ -33,13 +33,11 @@ attribute_hidden
|
||||
__libc_enable_asynccancel (void)
|
||||
{
|
||||
struct pthread *self = THREAD_SELF;
|
||||
int oldval;
|
||||
int newval;
|
||||
int oldval = THREAD_GETMEM (self, cancelhandling);
|
||||
|
||||
do
|
||||
while (1)
|
||||
{
|
||||
oldval = THREAD_GETMEM (self, cancelhandling);
|
||||
newval = oldval | CANCELTYPE_BITMASK;
|
||||
int newval = oldval | CANCELTYPE_BITMASK;
|
||||
|
||||
if (__builtin_expect ((oldval & CANCELED_BITMASK) != 0, 0))
|
||||
{
|
||||
@ -47,10 +45,14 @@ __libc_enable_asynccancel (void)
|
||||
if ((oldval & EXITING_BITMASK) != 0)
|
||||
break;
|
||||
|
||||
if (atomic_compare_and_exchange_bool_acq (&self->cancelhandling,
|
||||
newval, oldval))
|
||||
/* Somebody else modified the word, try again. */
|
||||
continue;
|
||||
int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
|
||||
newval, oldval);
|
||||
if (__builtin_expect (curval != oldval, 0))
|
||||
{
|
||||
/* Somebody else modified the word, try again. */
|
||||
oldval = curval;
|
||||
continue;
|
||||
}
|
||||
|
||||
THREAD_SETMEM (self, result, PTHREAD_CANCELED);
|
||||
|
||||
@ -58,9 +60,15 @@ __libc_enable_asynccancel (void)
|
||||
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
|
||||
oldval);
|
||||
if (__builtin_expect (curval == oldval, 1))
|
||||
break;
|
||||
|
||||
/* Prepare the next round. */
|
||||
oldval = curval;
|
||||
}
|
||||
while (atomic_compare_and_exchange_bool_acq (&self->cancelhandling,
|
||||
newval, oldval));
|
||||
|
||||
return oldval;
|
||||
}
|
||||
@ -76,19 +84,23 @@ __libc_disable_asynccancel (int oldtype)
|
||||
return;
|
||||
|
||||
struct pthread *self = THREAD_SELF;
|
||||
int oldval;
|
||||
int newval;
|
||||
int oldval = THREAD_GETMEM (self, cancelhandling);
|
||||
|
||||
do
|
||||
while (1)
|
||||
{
|
||||
oldval = THREAD_GETMEM (self, cancelhandling);
|
||||
newval = oldval & ~CANCELTYPE_BITMASK;
|
||||
int newval = oldval & ~CANCELTYPE_BITMASK;
|
||||
|
||||
if (newval == oldval)
|
||||
break;
|
||||
|
||||
int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
|
||||
oldval);
|
||||
if (__builtin_expect (curval == oldval, 1))
|
||||
break;
|
||||
|
||||
/* Prepare the next round. */
|
||||
oldval = curval;
|
||||
}
|
||||
while (atomic_compare_and_exchange_bool_acq (&self->cancelhandling, newval,
|
||||
oldval));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user