1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2008. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <pthread.h> |
---|
17 | #include <errno.h> |
---|
18 | |
---|
19 | #include <rtems/system.h> |
---|
20 | #include <rtems/score/chain.h> |
---|
21 | #include <rtems/score/isr.h> |
---|
22 | #include <rtems/score/thread.h> |
---|
23 | #include <rtems/score/wkspace.h> |
---|
24 | #include <rtems/posix/cancel.h> |
---|
25 | #include <rtems/posix/pthread.h> |
---|
26 | #include <rtems/posix/threadsup.h> |
---|
27 | |
---|
28 | /*PAGE |
---|
29 | * |
---|
30 | * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 |
---|
31 | */ |
---|
32 | |
---|
33 | void pthread_cleanup_push( |
---|
34 | void (*routine)( void * ), |
---|
35 | void *arg |
---|
36 | ) |
---|
37 | { |
---|
38 | POSIX_Cancel_Handler_control *handler; |
---|
39 | Chain_Control *handler_stack; |
---|
40 | POSIX_API_Control *thread_support; |
---|
41 | |
---|
42 | /* |
---|
43 | * The POSIX standard does not address what to do when the routine |
---|
44 | * is NULL. It also does not address what happens when we cannot |
---|
45 | * allocate memory or anything else bad happens. |
---|
46 | */ |
---|
47 | if ( !routine ) |
---|
48 | return; |
---|
49 | |
---|
50 | _Thread_Disable_dispatch(); |
---|
51 | handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) ); |
---|
52 | |
---|
53 | if ( handler ) { |
---|
54 | thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; |
---|
55 | |
---|
56 | handler_stack = &thread_support->Cancellation_Handlers; |
---|
57 | |
---|
58 | handler->routine = routine; |
---|
59 | handler->arg = arg; |
---|
60 | |
---|
61 | _Chain_Append( handler_stack, &handler->Node ); |
---|
62 | } |
---|
63 | _Thread_Enable_dispatch(); |
---|
64 | } |
---|