aboutsummaryrefslogtreecommitdiff
path: root/nptl/cancellation.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-04-05 05:21:15 +0000
committerUlrich Drepper <drepper@redhat.com>2003-04-05 05:21:15 +0000
commitb22d701bb72b928526efff83c019b912f469af72 (patch)
tree4474c99dbe6f90a380c378817307646f6f8eff5c /nptl/cancellation.c
parent3242201746d74bfbccb8267f8b2e81a9478bf78b (diff)
downloadglibc-b22d701bb72b928526efff83c019b912f469af72.tar
glibc-b22d701bb72b928526efff83c019b912f469af72.tar.gz
glibc-b22d701bb72b928526efff83c019b912f469af72.tar.bz2
glibc-b22d701bb72b928526efff83c019b912f469af72.zip
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.
Diffstat (limited to 'nptl/cancellation.c')
-rw-r--r--nptl/cancellation.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/nptl/cancellation.c b/nptl/cancellation.c
index d88cae3aa7..c7477d87df 100644
--- a/nptl/cancellation.c
+++ b/nptl/cancellation.c
@@ -20,7 +20,6 @@
#include <setjmp.h>
#include <stdlib.h>
#include "pthreadP.h"
-#include "atomic.h"
/* The next two functions are similar to pthread_setcanceltype() but
@@ -31,18 +30,18 @@ attribute_hidden
__pthread_enable_asynccancel (void)
{
struct pthread *self = THREAD_SELF;
- int oldval;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
while (1)
{
- oldval = THREAD_GETMEM (self, cancelhandling);
int newval = oldval | CANCELTYPE_BITMASK;
if (newval == oldval)
break;
- 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))
{
@@ -52,6 +51,9 @@ __pthread_enable_asynccancel (void)
break;
}
+
+ /* Prepare the next round. */
+ oldval = curval;
}
return oldval;
@@ -63,17 +65,22 @@ internal_function attribute_hidden
__pthread_enable_asynccancel_2 (int *oldvalp)
{
struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
while (1)
{
- int oldval = *oldvalp = THREAD_GETMEM (self, cancelhandling);
int newval = oldval | CANCELTYPE_BITMASK;
if (newval == oldval)
break;
- if (! atomic_compare_and_exchange_bool_acq (&self->cancelhandling,
- newval, oldval))
+ /* We have to store the value before enablying asynchronous
+ cancellation. */
+ *oldvalp = 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))
{
@@ -97,17 +104,21 @@ __pthread_disable_asynccancel (int oldtype)
return;
struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
while (1)
{
- int oldval = THREAD_GETMEM (self, cancelhandling);
int newval = oldval & ~CANCELTYPE_BITMASK;
if (newval == oldval)
break;
- 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))
break;
+
+ /* Prepare the next round. */
+ oldval = curval;
}
}