12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #include <stdlib.h>
- #include "pthreadP.h"
- void
- __cleanup_fct_attribute
- __pthread_register_cancel_defer (__pthread_unwind_buf_t *buf)
- {
- struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
- struct pthread *self = THREAD_SELF;
-
- ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
- ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup);
- int cancelhandling = THREAD_GETMEM (self, cancelhandling);
-
- if (__builtin_expect (cancelhandling & CANCELTYPE_BITMASK, 0))
- while (1)
- {
- int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
- cancelhandling
- & ~CANCELTYPE_BITMASK,
- cancelhandling);
- if (__builtin_expect (curval == cancelhandling, 1))
-
- break;
-
- cancelhandling = curval;
- }
- ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK
- ? PTHREAD_CANCEL_ASYNCHRONOUS
- : PTHREAD_CANCEL_DEFERRED);
-
- THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
- }
- void
- __cleanup_fct_attribute
- __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf)
- {
- struct pthread *self = THREAD_SELF;
- struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
- THREAD_SETMEM (self, cleanup_jmp_buf, ibuf->priv.data.prev);
- int cancelhandling;
- if (ibuf->priv.data.canceltype != PTHREAD_CANCEL_DEFERRED
- && ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
- & CANCELTYPE_BITMASK) == 0)
- {
- while (1)
- {
- int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
- cancelhandling
- | CANCELTYPE_BITMASK,
- cancelhandling);
- if (__builtin_expect (curval == cancelhandling, 1))
-
- break;
-
- cancelhandling = curval;
- }
- CANCELLATION_P (self);
- }
- }
|