1 | /* |
---|
2 | * Signal Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1997. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/rtems/status.h> |
---|
18 | #include <rtems/rtems/asr.h> |
---|
19 | #include <rtems/score/isr.h> |
---|
20 | #include <rtems/rtems/modes.h> |
---|
21 | #include <rtems/rtems/signal.h> |
---|
22 | #include <rtems/score/thread.h> |
---|
23 | #include <rtems/rtems/tasks.h> |
---|
24 | |
---|
25 | /*PAGE |
---|
26 | * |
---|
27 | * _Signal_Manager_initialization |
---|
28 | * |
---|
29 | * This routine initializes all signal manager related data structures. |
---|
30 | * |
---|
31 | * Input parameters: NONE |
---|
32 | * |
---|
33 | * Output parameters: NONE |
---|
34 | */ |
---|
35 | |
---|
36 | void _Signal_Manager_initialization( void ) |
---|
37 | { |
---|
38 | /* |
---|
39 | * Register the MP Process Packet routine. |
---|
40 | */ |
---|
41 | |
---|
42 | _MPCI_Register_packet_processor( |
---|
43 | MP_PACKET_SIGNAL, |
---|
44 | _Signal_MP_Process_packet |
---|
45 | ); |
---|
46 | } |
---|
47 | |
---|
48 | /*PAGE |
---|
49 | * |
---|
50 | * rtems_signal_catch |
---|
51 | * |
---|
52 | * This directive allows a thread to specify what action to take when |
---|
53 | * catching signals. |
---|
54 | * |
---|
55 | * Input parameters: |
---|
56 | * handler - address of asynchronous signal routine (asr) |
---|
57 | * ( NULL indicates asr is invalid ) |
---|
58 | * mode_set - mode value for asr |
---|
59 | * |
---|
60 | * Output parameters: |
---|
61 | * RTEMS_SUCCESSFUL - always succeeds |
---|
62 | */ |
---|
63 | |
---|
64 | rtems_status_code rtems_signal_catch( |
---|
65 | rtems_asr_entry asr_handler, |
---|
66 | rtems_mode mode_set |
---|
67 | ) |
---|
68 | { |
---|
69 | Thread_Control *executing; |
---|
70 | RTEMS_API_Control *api; |
---|
71 | ASR_Information *asr; |
---|
72 | |
---|
73 | /* XXX normalize mode */ |
---|
74 | executing = _Thread_Executing; |
---|
75 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
76 | asr = &api->Signal; |
---|
77 | |
---|
78 | _Thread_Disable_dispatch(); /* cannot reschedule while */ |
---|
79 | /* the thread is inconsistent */ |
---|
80 | |
---|
81 | if ( !_ASR_Is_null_handler( asr_handler ) ) { |
---|
82 | asr->mode_set = mode_set; |
---|
83 | asr->handler = asr_handler; |
---|
84 | } |
---|
85 | else |
---|
86 | _ASR_Initialize( asr ); |
---|
87 | _Thread_Enable_dispatch(); |
---|
88 | return RTEMS_SUCCESSFUL; |
---|
89 | } |
---|
90 | |
---|
91 | /*PAGE |
---|
92 | * |
---|
93 | * rtems_signal_send |
---|
94 | * |
---|
95 | * This directive allows a thread to send signals to a thread. |
---|
96 | * |
---|
97 | * Input parameters: |
---|
98 | * id - thread id |
---|
99 | * signal_set - signal set |
---|
100 | * |
---|
101 | * Output parameters: |
---|
102 | * RTEMS_SUCCESSFUL - if successful |
---|
103 | * error code - if unsuccessful |
---|
104 | */ |
---|
105 | |
---|
106 | rtems_status_code rtems_signal_send( |
---|
107 | Objects_Id id, |
---|
108 | rtems_signal_set signal_set |
---|
109 | ) |
---|
110 | { |
---|
111 | register Thread_Control *the_thread; |
---|
112 | Objects_Locations location; |
---|
113 | RTEMS_API_Control *api; |
---|
114 | ASR_Information *asr; |
---|
115 | |
---|
116 | the_thread = _Thread_Get( id, &location ); |
---|
117 | switch ( location ) { |
---|
118 | case OBJECTS_ERROR: |
---|
119 | return RTEMS_INVALID_ID; |
---|
120 | case OBJECTS_REMOTE: |
---|
121 | return _Signal_MP_Send_request_packet( |
---|
122 | SIGNAL_MP_SEND_REQUEST, |
---|
123 | id, |
---|
124 | signal_set |
---|
125 | ); |
---|
126 | case OBJECTS_LOCAL: |
---|
127 | api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
128 | asr = &api->Signal; |
---|
129 | |
---|
130 | if ( ! _ASR_Is_null_handler( asr->handler ) ) { |
---|
131 | if ( asr->is_enabled ) { |
---|
132 | _ASR_Post_signals( signal_set, &asr->signals_posted ); |
---|
133 | |
---|
134 | the_thread->do_post_task_switch_extension = TRUE; |
---|
135 | |
---|
136 | if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) ) |
---|
137 | _ISR_Signals_to_thread_executing = TRUE; |
---|
138 | } else { |
---|
139 | _ASR_Post_signals( signal_set, &asr->signals_pending ); |
---|
140 | } |
---|
141 | _Thread_Enable_dispatch(); |
---|
142 | return RTEMS_SUCCESSFUL; |
---|
143 | } |
---|
144 | _Thread_Enable_dispatch(); |
---|
145 | return RTEMS_NOT_DEFINED; |
---|
146 | } |
---|
147 | |
---|
148 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
149 | } |
---|