1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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/posix/cancel.h> |
---|
24 | #include <rtems/posix/pthread.h> |
---|
25 | #include <rtems/posix/threadsup.h> |
---|
26 | |
---|
27 | /* |
---|
28 | * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 |
---|
29 | */ |
---|
30 | |
---|
31 | int pthread_setcancelstate( |
---|
32 | int state, |
---|
33 | int *oldstate |
---|
34 | ) |
---|
35 | { |
---|
36 | POSIX_API_Control *thread_support; |
---|
37 | |
---|
38 | /* |
---|
39 | * Don't even think about deleting a resource from an ISR. |
---|
40 | * Besides this request is supposed to be for _Thread_Executing |
---|
41 | * and the ISR context is not a thread. |
---|
42 | */ |
---|
43 | |
---|
44 | if ( _ISR_Is_in_progress() ) |
---|
45 | return EPROTO; |
---|
46 | |
---|
47 | if ( !oldstate ) |
---|
48 | return EINVAL; |
---|
49 | |
---|
50 | if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE ) |
---|
51 | return EINVAL; |
---|
52 | |
---|
53 | thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; |
---|
54 | |
---|
55 | _Thread_Disable_dispatch(); |
---|
56 | *oldstate = thread_support->cancelability_state; |
---|
57 | thread_support->cancelability_state = state; |
---|
58 | |
---|
59 | _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch(_Thread_Executing); |
---|
60 | |
---|
61 | /* |
---|
62 | * _Thread_Enable_dispatch is invoked by above call. |
---|
63 | */ |
---|
64 | |
---|
65 | return 0; |
---|
66 | } |
---|