1 | /* |
---|
2 | * Multiprocessing Support for the Thread Handler |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * All rights assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
10 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
11 | * notice must appear in all copies of this file and its derivatives. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/priority.h> |
---|
18 | #include <rtems/thread.h> |
---|
19 | #include <rtems/wkspace.h> |
---|
20 | |
---|
21 | /*PAGE |
---|
22 | * |
---|
23 | * _Thread_MP_Handler_initialization |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | void _Thread_MP_Handler_initialization ( |
---|
28 | unsigned32 maximum_proxies |
---|
29 | ) |
---|
30 | { |
---|
31 | |
---|
32 | _Chain_Initialize_empty( &_Thread_MP_Active_proxies ); |
---|
33 | |
---|
34 | if ( maximum_proxies == 0 ) { |
---|
35 | _Chain_Initialize_empty( &_Thread_MP_Inactive_proxies ); |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | _Chain_Initialize( |
---|
41 | &_Thread_MP_Inactive_proxies, |
---|
42 | _Workspace_Allocate_or_fatal_error( |
---|
43 | maximum_proxies * sizeof( Thread_Proxy_control ) |
---|
44 | ), |
---|
45 | maximum_proxies, |
---|
46 | sizeof( Thread_Proxy_control ) |
---|
47 | ); |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | /*PAGE |
---|
52 | * |
---|
53 | * _Thread_MP_Allocate_proxy |
---|
54 | * |
---|
55 | */ |
---|
56 | |
---|
57 | Thread_Control *_Thread_MP_Allocate_proxy ( |
---|
58 | States_Control the_state |
---|
59 | ) |
---|
60 | { |
---|
61 | Thread_Control *the_thread; |
---|
62 | Thread_Proxy_control *the_proxy; |
---|
63 | |
---|
64 | the_thread = (Thread_Control *)_Chain_Get( &_Thread_MP_Inactive_proxies ); |
---|
65 | |
---|
66 | if ( !_Thread_Is_null( the_thread ) ) { |
---|
67 | |
---|
68 | the_proxy = (Thread_Proxy_control *) the_thread; |
---|
69 | |
---|
70 | _Thread_Executing->Wait.return_code = RTEMS_PROXY_BLOCKING; |
---|
71 | |
---|
72 | the_proxy->receive_packet = _Thread_MP_Receive->receive_packet; |
---|
73 | |
---|
74 | the_proxy->Object.id = _Thread_MP_Receive->receive_packet->source_tid; |
---|
75 | |
---|
76 | the_proxy->current_priority = |
---|
77 | _Thread_MP_Receive->receive_packet->source_priority; |
---|
78 | |
---|
79 | the_proxy->current_state = _States_Set( STATES_DORMANT, the_state ); |
---|
80 | |
---|
81 | the_proxy->Wait = _Thread_Executing->Wait; |
---|
82 | |
---|
83 | _Chain_Append( &_Thread_MP_Active_proxies, &the_proxy->Active ); |
---|
84 | |
---|
85 | return the_thread; |
---|
86 | } |
---|
87 | |
---|
88 | rtems_fatal_error_occurred( RTEMS_TOO_MANY ); |
---|
89 | |
---|
90 | /* |
---|
91 | * NOTE: The following return insures that the compiler will |
---|
92 | * think that all paths return a value. |
---|
93 | */ |
---|
94 | |
---|
95 | return NULL; |
---|
96 | } |
---|
97 | |
---|
98 | /*PAGE |
---|
99 | * |
---|
100 | * _Thread_MP_Find_proxy |
---|
101 | * |
---|
102 | */ |
---|
103 | |
---|
104 | /* |
---|
105 | * The following macro provides the offset of the Active element |
---|
106 | * in the Thread_Proxy_control structure. This is the logical |
---|
107 | * equivalent of the POSITION attribute in Ada. |
---|
108 | */ |
---|
109 | |
---|
110 | #define _Thread_MP_Proxy_Active_offset \ |
---|
111 | ((unsigned32)&(((Thread_Proxy_control *)0))->Active) |
---|
112 | |
---|
113 | Thread_Control *_Thread_MP_Find_proxy ( |
---|
114 | Objects_Id the_id |
---|
115 | ) |
---|
116 | { |
---|
117 | |
---|
118 | Chain_Node *proxy_node; |
---|
119 | Thread_Control *the_thread; |
---|
120 | ISR_Level level; |
---|
121 | |
---|
122 | restart: |
---|
123 | |
---|
124 | _ISR_Disable( level ); |
---|
125 | |
---|
126 | for ( proxy_node = _Thread_MP_Active_proxies.first; |
---|
127 | !_Chain_Is_tail( &_Thread_MP_Active_proxies, proxy_node ) ; |
---|
128 | ) { |
---|
129 | |
---|
130 | the_thread = _Addresses_Subtract_offset( |
---|
131 | proxy_node, |
---|
132 | _Thread_MP_Proxy_Active_offset |
---|
133 | ); |
---|
134 | |
---|
135 | if ( _Objects_Are_ids_equal( the_thread->Object.id, the_id ) ) { |
---|
136 | _ISR_Enable( level ); |
---|
137 | return the_thread; |
---|
138 | } |
---|
139 | |
---|
140 | _ISR_Flash( level ); |
---|
141 | |
---|
142 | proxy_node = proxy_node->next; |
---|
143 | |
---|
144 | /* |
---|
145 | * A proxy which is only dormant is not in a blocking state. |
---|
146 | * Therefore, we are looking at proxy which has been moved from |
---|
147 | * active to inactive chain (by an ISR) and need to restart |
---|
148 | * the search. |
---|
149 | */ |
---|
150 | |
---|
151 | if ( _States_Is_only_dormant( the_thread->current_state ) ) { |
---|
152 | _ISR_Enable( level ); |
---|
153 | goto restart; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | _ISR_Enable( level ); |
---|
158 | return NULL; |
---|
159 | } |
---|
160 | |
---|
161 | /*PAGE |
---|
162 | * |
---|
163 | * _Thread_MP_Block |
---|
164 | * |
---|
165 | */ |
---|
166 | |
---|
167 | void _Thread_MP_Block( void ) |
---|
168 | { |
---|
169 | ISR_Level level; |
---|
170 | |
---|
171 | _ISR_Disable( level ); |
---|
172 | |
---|
173 | if ( _Thread_MP_Receive->Notepads[ 0 ] != 0 ) { |
---|
174 | _Priority_Remove_from_bit_map( &_Thread_MP_Receive->Priority_map ); |
---|
175 | |
---|
176 | _Thread_MP_Receive->current_state = STATES_SUSPENDED; |
---|
177 | |
---|
178 | _ISR_Flash( level ); |
---|
179 | |
---|
180 | _Thread_Calculate_heir(); |
---|
181 | |
---|
182 | _Context_Switch_necessary = TRUE; |
---|
183 | |
---|
184 | _ISR_Enable( level ); |
---|
185 | |
---|
186 | _Thread_Dispatch_disable_level = 0; |
---|
187 | |
---|
188 | _Thread_Dispatch(); |
---|
189 | |
---|
190 | return; |
---|
191 | |
---|
192 | } |
---|
193 | _ISR_Enable( level ); |
---|
194 | |
---|
195 | } |
---|
196 | |
---|
197 | /*PAGE |
---|
198 | * |
---|
199 | * _Thread_MP_Ready |
---|
200 | * |
---|
201 | */ |
---|
202 | |
---|
203 | void _Thread_MP_Ready( void ) |
---|
204 | { |
---|
205 | ISR_Level level; |
---|
206 | |
---|
207 | _ISR_Disable( level ); |
---|
208 | |
---|
209 | if ( _States_Is_suspended( _Thread_MP_Receive->current_state ) ) { |
---|
210 | _Priority_Add_to_bit_map( &_Thread_MP_Receive->Priority_map ); |
---|
211 | |
---|
212 | _Thread_MP_Receive->current_state = STATES_READY; |
---|
213 | |
---|
214 | _Thread_Heir = _Thread_MP_Receive; |
---|
215 | |
---|
216 | _Context_Switch_necessary = TRUE; |
---|
217 | |
---|
218 | _ISR_Enable( level ); |
---|
219 | |
---|
220 | if ( _Thread_Is_dispatching_enabled() ) |
---|
221 | _Thread_Dispatch(); |
---|
222 | |
---|
223 | } else { |
---|
224 | |
---|
225 | _Thread_MP_Receive->Notepads[ 0 ] = 0; |
---|
226 | _ISR_Enable( level ); |
---|
227 | |
---|
228 | } |
---|
229 | } |
---|