1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX Signals Thread Unlock |
---|
5 | * @ingroup POSIX_SIGNALS |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
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 <errno.h> |
---|
22 | #include <pthread.h> |
---|
23 | #include <signal.h> |
---|
24 | |
---|
25 | #include <rtems/system.h> |
---|
26 | #include <rtems/score/isr.h> |
---|
27 | #include <rtems/score/threadimpl.h> |
---|
28 | #include <rtems/score/threadqimpl.h> |
---|
29 | #include <rtems/score/watchdogimpl.h> |
---|
30 | #include <rtems/score/wkspace.h> |
---|
31 | #include <rtems/seterr.h> |
---|
32 | #include <rtems/posix/threadsup.h> |
---|
33 | #include <rtems/posix/psignalimpl.h> |
---|
34 | #include <rtems/posix/pthreadimpl.h> |
---|
35 | #include <stdio.h> |
---|
36 | |
---|
37 | static bool _POSIX_signals_Unblock_thread_done( |
---|
38 | Thread_Control *the_thread, |
---|
39 | POSIX_API_Control *api, |
---|
40 | bool status |
---|
41 | ) |
---|
42 | { |
---|
43 | _Thread_Add_post_switch_action( the_thread, &api->Signal_action ); |
---|
44 | |
---|
45 | return status; |
---|
46 | } |
---|
47 | |
---|
48 | bool _POSIX_signals_Unblock_thread( |
---|
49 | Thread_Control *the_thread, |
---|
50 | int signo, |
---|
51 | siginfo_t *info |
---|
52 | ) |
---|
53 | { |
---|
54 | POSIX_API_Control *api; |
---|
55 | sigset_t mask; |
---|
56 | siginfo_t *the_info = NULL; |
---|
57 | |
---|
58 | api = the_thread->API_Extensions[ THREAD_API_POSIX ]; |
---|
59 | |
---|
60 | mask = signo_to_mask( signo ); |
---|
61 | |
---|
62 | /* |
---|
63 | * Is the thread is specifically waiting for a signal? |
---|
64 | */ |
---|
65 | |
---|
66 | if ( _States_Is_interruptible_signal( the_thread->current_state ) ) { |
---|
67 | |
---|
68 | if ( (the_thread->Wait.option & mask) || (~api->signals_blocked & mask) ) { |
---|
69 | the_thread->Wait.return_code = EINTR; |
---|
70 | |
---|
71 | the_info = (siginfo_t *) the_thread->Wait.return_argument; |
---|
72 | |
---|
73 | if ( !info ) { |
---|
74 | the_info->si_signo = signo; |
---|
75 | the_info->si_code = SI_USER; |
---|
76 | the_info->si_value.sival_int = 0; |
---|
77 | } else { |
---|
78 | *the_info = *info; |
---|
79 | } |
---|
80 | |
---|
81 | _Thread_queue_Extract_with_proxy( the_thread ); |
---|
82 | return _POSIX_signals_Unblock_thread_done( the_thread, api, true ); |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | * This should only be reached via pthread_kill(). |
---|
87 | */ |
---|
88 | |
---|
89 | return _POSIX_signals_Unblock_thread_done( the_thread, api, false ); |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * Thread is not waiting due to a sigwait. |
---|
94 | */ |
---|
95 | if ( ~api->signals_blocked & mask ) { |
---|
96 | |
---|
97 | /* |
---|
98 | * The thread is interested in this signal. We are going |
---|
99 | * to post it. We have a few broad cases: |
---|
100 | * + If it is blocked on an interruptible signal, THEN |
---|
101 | * we unblock the thread. |
---|
102 | * + If it is in the ready state AND |
---|
103 | * we are sending from an ISR AND |
---|
104 | * it is the interrupted thread AND |
---|
105 | * it is not blocked, THEN |
---|
106 | * we need to dispatch at the end of this ISR. |
---|
107 | * + Any other combination, do nothing. |
---|
108 | */ |
---|
109 | |
---|
110 | if ( _States_Is_interruptible_by_signal( the_thread->current_state ) ) { |
---|
111 | the_thread->Wait.return_code = EINTR; |
---|
112 | _Thread_queue_Extract_with_proxy( the_thread ); |
---|
113 | } |
---|
114 | } |
---|
115 | return _POSIX_signals_Unblock_thread_done( the_thread, api, false ); |
---|
116 | } |
---|