Back to index

glibc  2.9
Functions
cleanup_defer.c File Reference
#include <stdlib.h>
#include "pthreadP.h"

Go to the source code of this file.

Functions

void __cleanup_fct_attribute __pthread_register_cancel_defer (__pthread_unwind_buf_t *buf)
void __cleanup_fct_attribute __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf)

Function Documentation

Definition at line 26 of file cleanup_defer.c.

{
  struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
  struct pthread *self = THREAD_SELF;

  /* Store old info.  */
  ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
  ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup);

  int cancelhandling = THREAD_GETMEM (self, cancelhandling);

  /* Disable asynchronous cancellation for now.  */
  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))
         /* Successfully replaced the value.  */
         break;

       /* Prepare for the next round.  */
       cancelhandling = curval;
      }

  ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK
                            ? PTHREAD_CANCEL_ASYNCHRONOUS
                            : PTHREAD_CANCEL_DEFERRED);

  /* Store the new cleanup handler info.  */
  THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
}

Definition at line 64 of file cleanup_defer.c.

{
  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))
           /* Successfully replaced the value.  */
           break;

         /* Prepare for the next round.  */
         cancelhandling = curval;
       }

      CANCELLATION_P (self);
    }
}