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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <pthread.h> |
---|
22 | #include <errno.h> |
---|
23 | |
---|
24 | #include <rtems/system.h> |
---|
25 | #include <rtems/score/chain.h> |
---|
26 | #include <rtems/score/isr.h> |
---|
27 | #include <rtems/score/thread.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | #include <rtems/posix/cancel.h> |
---|
30 | #include <rtems/posix/pthreadimpl.h> |
---|
31 | #include <rtems/posix/threadsup.h> |
---|
32 | |
---|
33 | void _POSIX_Threads_cancel_run( |
---|
34 | Thread_Control *the_thread |
---|
35 | ) |
---|
36 | { |
---|
37 | POSIX_Cancel_Handler_control *handler; |
---|
38 | Chain_Control *handler_stack; |
---|
39 | POSIX_API_Control *thread_support; |
---|
40 | ISR_Level level; |
---|
41 | |
---|
42 | thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ]; |
---|
43 | |
---|
44 | handler_stack = &thread_support->Cancellation_Handlers; |
---|
45 | |
---|
46 | thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE; |
---|
47 | |
---|
48 | while ( !_Chain_Is_empty( handler_stack ) ) { |
---|
49 | _ISR_Disable( level ); |
---|
50 | handler = (POSIX_Cancel_Handler_control *) |
---|
51 | _Chain_Tail( handler_stack )->previous; |
---|
52 | _Chain_Extract_unprotected( &handler->Node ); |
---|
53 | _ISR_Enable( level ); |
---|
54 | |
---|
55 | (*handler->routine)( handler->arg ); |
---|
56 | |
---|
57 | _Workspace_Free( handler ); |
---|
58 | } |
---|
59 | } |
---|