123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include <setjmp.h>
- #include <stdlib.h>
- #include "pthreadP.h"
- int
- attribute_hidden
- __pthread_enable_asynccancel (void)
- {
- struct pthread *self = THREAD_SELF;
- int oldval = THREAD_GETMEM (self, cancelhandling);
- while (1)
- {
- 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))
- {
- if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
- {
- THREAD_SETMEM (self, result, PTHREAD_CANCELED);
- __do_cancel ();
- }
- break;
- }
-
- oldval = curval;
- }
- return oldval;
- }
- void
- internal_function attribute_hidden
- __pthread_disable_asynccancel (int oldtype)
- {
-
- if (oldtype & CANCELTYPE_BITMASK)
- return;
- struct pthread *self = THREAD_SELF;
- int newval;
- int oldval = THREAD_GETMEM (self, cancelhandling);
- while (1)
- {
- newval = oldval & ~CANCELTYPE_BITMASK;
- int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
- oldval);
- if (__builtin_expect (curval == oldval, 1))
- break;
-
- oldval = curval;
- }
-
- while (__builtin_expect ((newval & (CANCELING_BITMASK | CANCELED_BITMASK))
- == CANCELING_BITMASK, 0))
- {
- lll_futex_wait (&self->cancelhandling, newval, LLL_PRIVATE);
- newval = THREAD_GETMEM (self, cancelhandling);
- }
- }
|