Back to index

glibc  2.9
Functions
cancel.c File Reference
#include <errno.h>
#include <libc-internal.h>
#include "pthread.h"
#include "internals.h"
#include "spinlock.h"
#include "restart.h"

Go to the source code of this file.

Functions

int __pthread_setcancelstate (int state, int *oldstate)
 strong_alias (__pthread_setcancelstate, pthread_setcancelstate)
int __pthread_setcanceltype (int type, int *oldtype)
 strong_alias (__pthread_setcanceltype, pthread_setcanceltype)
int attribute_hidden __pthread_enable_asynccancel (void)
void internal_function
attribute_hidden 
__pthread_disable_asynccancel (int oldtype)
int pthread_cancel (pthread_t thread)
void pthread_testcancel (void)
void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, void(*routine)(void *), void *arg)
void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer, int execute)
void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer, void(*routine)(void *), void *arg)
void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, int execute)
void __pthread_perform_cleanup (char *currentframe)

Function Documentation

Definition at line 82 of file cancel.c.

{
  pthread_descr self = thread_self();
  THREAD_SETMEM(self, p_canceltype, oldtype);
}

Here is the caller graph for this function:

Definition at line 69 of file cancel.c.

Here is the caller graph for this function:

void __pthread_perform_cleanup ( char *  currentframe)

Definition at line 202 of file cancel.c.

{
  pthread_descr self = thread_self();
  struct _pthread_cleanup_buffer *c = THREAD_GETMEM(self, p_cleanup);
  struct _pthread_cleanup_buffer *last;

  if (c != NULL)
    while (FRAME_LEFT (currentframe, c))
      {
       last = c;
       c = c->__prev;

       if (c == NULL || FRAME_LEFT (last, c))
         {
           c = NULL;
           break;
         }
      }

  while (c != NULL)
    {
      c->__routine(c->__arg);

      last = c;
      c = c->__prev;

      if (FRAME_LEFT (last, c))
       break;
    }

  /* And the TSD which needs special help.  */
  __libc_thread_freeres ();
}

Here is the caller graph for this function:

int __pthread_setcancelstate ( int  state,
int oldstate 
)
int __pthread_setcanceltype ( int  type,
int oldtype 
)

Definition at line 48 of file cancel.c.

{
  pthread_descr self = thread_self();
  if (type < PTHREAD_CANCEL_DEFERRED || type > PTHREAD_CANCEL_ASYNCHRONOUS)
    return EINVAL;
  if (oldtype != NULL) *oldtype = THREAD_GETMEM(self, p_canceltype);
  THREAD_SETMEM(self, p_canceltype, type);
  if (THREAD_GETMEM(self, p_canceled) &&
      THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE &&
      THREAD_GETMEM(self, p_canceltype) == PTHREAD_CANCEL_ASYNCHRONOUS)
    __pthread_do_exit(PTHREAD_CANCELED, CURRENT_STACK_FRAME);
  return 0;
}
void _pthread_cleanup_pop ( struct _pthread_cleanup_buffer buffer,
int  execute 
)

Definition at line 167 of file cancel.c.

{
  pthread_descr self = thread_self();
  if (execute) buffer->__routine(buffer->__arg);
  THREAD_SETMEM(self, p_cleanup, buffer->__prev);
}

Here is the caller graph for this function:

void _pthread_cleanup_pop_restore ( struct _pthread_cleanup_buffer buffer,
int  execute 
)

Definition at line 189 of file cancel.c.

Here is the call graph for this function:

void _pthread_cleanup_push ( struct _pthread_cleanup_buffer buffer,
void(*)(void *)  routine,
void *  arg 
)

Definition at line 155 of file cancel.c.

{
  pthread_descr self = thread_self();
  buffer->__routine = routine;
  buffer->__arg = arg;
  buffer->__prev = THREAD_GETMEM(self, p_cleanup);
  if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev))
    buffer->__prev = NULL;
  THREAD_SETMEM(self, p_cleanup, buffer);
}

Here is the caller graph for this function:

void _pthread_cleanup_push_defer ( struct _pthread_cleanup_buffer buffer,
void(*)(void *)  routine,
void *  arg 
)

Definition at line 175 of file cancel.c.

{
  pthread_descr self = thread_self();
  buffer->__routine = routine;
  buffer->__arg = arg;
  buffer->__canceltype = THREAD_GETMEM(self, p_canceltype);
  buffer->__prev = THREAD_GETMEM(self, p_cleanup);
  if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev))
    buffer->__prev = NULL;
  THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_DEFERRED);
  THREAD_SETMEM(self, p_cleanup, buffer);
}

Definition at line 89 of file cancel.c.

{
  pthread_handle handle = thread_handle(thread);
  int pid;
  int dorestart = 0;
  pthread_descr th;
  pthread_extricate_if *pextricate;
  int already_canceled;

  __pthread_lock(&handle->h_lock, NULL);
  if (invalid_handle(handle, thread)) {
    __pthread_unlock(&handle->h_lock);
    return ESRCH;
  }

  th = handle->h_descr;

  already_canceled = th->p_canceled;
  th->p_canceled = 1;

  if (th->p_cancelstate == PTHREAD_CANCEL_DISABLE || already_canceled) {
    __pthread_unlock(&handle->h_lock);
    return 0;
  }

  pextricate = th->p_extricate;
  pid = th->p_pid;

  /* If the thread has registered an extrication interface, then
     invoke the interface. If it returns 1, then we succeeded in
     dequeuing the thread from whatever waiting object it was enqueued
     with. In that case, it is our responsibility to wake it up.
     And also to set the p_woken_by_cancel flag so the woken thread
     can tell that it was woken by cancellation. */

  if (pextricate != NULL) {
    dorestart = pextricate->pu_extricate_func(pextricate->pu_object, th);
    th->p_woken_by_cancel = dorestart;
  }

  __pthread_unlock(&handle->h_lock);

  /* If the thread has suspended or is about to, then we unblock it by
     issuing a restart, instead of a cancel signal. Otherwise we send
     the cancel signal to unblock the thread from a cancellation point,
     or to initiate asynchronous cancellation. The restart is needed so
     we have proper accounting of restarts; suspend decrements the thread's
     resume count, and restart() increments it.  This also means that suspend's
     handling of the cancel signal is obsolete. */

  if (dorestart)
    restart(th);
  else
    kill(pid, __pthread_sig_cancel);

  return 0;
}

Here is the caller graph for this function:

void pthread_testcancel ( void  )

Definition at line 147 of file cancel.c.

Here is the caller graph for this function: