source: rtems/cpukit/posix/src/cancelrun.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Executes a thread's cancellation handlers
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22
23#include <rtems/score/thread.h>
24#include <rtems/score/threaddispatch.h>
25#include <rtems/posix/cancel.h>
26#include <rtems/posix/threadsup.h>
27
28#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
29
30#include <rtems/score/chainimpl.h>
31#include <rtems/score/isr.h>
32#include <rtems/score/wkspace.h>
33#include <rtems/posix/pthreadimpl.h>
34
35void _POSIX_Threads_cancel_run(
36  Thread_Control *the_thread
37)
38{
39  POSIX_Cancel_Handler_control      *handler;
40  Chain_Control                     *handler_stack;
41  POSIX_API_Control                 *thread_support;
42  ISR_Level                          level;
43
44  thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
45
46  handler_stack = &thread_support->Cancellation_Handlers;
47
48  thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
49
50  while ( !_Chain_Is_empty( handler_stack ) ) {
51    _ISR_Disable( level );
52      handler = (POSIX_Cancel_Handler_control *)
53           _Chain_Tail( handler_stack )->previous;
54      _Chain_Extract_unprotected( &handler->Node );
55    _ISR_Enable( level );
56
57    (*handler->routine)( handler->arg );
58
59    _Workspace_Free( handler );
60  }
61}
62
63#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
64
65void _POSIX_Threads_cancel_run(
66  Thread_Control *the_thread
67)
68{
69  struct _pthread_cleanup_context *context;
70  POSIX_API_Control               *thread_support;
71
72  _Thread_Disable_dispatch();
73
74  thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
75  thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
76
77  context = thread_support->last_cleanup_context;
78  thread_support->last_cleanup_context = NULL;
79
80  _Thread_Enable_dispatch();
81
82  while ( context != NULL ) {
83    ( *context->_routine )( context->_arg );
84
85    context = context->_previous;
86  }
87}
88
89#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
Note: See TracBrowser for help on using the repository browser.