1 | /* thread.inl |
---|
2 | * |
---|
3 | * This file contains the macro implementation of the inlined |
---|
4 | * routines from the Thread handler. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1998. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * Copyright assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.OARcorp.com/rtems/license.html. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef __THREAD_inl |
---|
18 | #define __THREAD_inl |
---|
19 | |
---|
20 | /*PAGE |
---|
21 | * |
---|
22 | * _Thread_Stop_multitasking |
---|
23 | * |
---|
24 | * DESCRIPTION: |
---|
25 | * |
---|
26 | * This routine halts multitasking and returns control to |
---|
27 | * the "thread" (i.e. the BSP) which initially invoked the |
---|
28 | * routine which initialized the system. |
---|
29 | */ |
---|
30 | |
---|
31 | RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void ) |
---|
32 | { |
---|
33 | _Context_Switch( &_Thread_Executing->Registers, &_Thread_BSP_context ); |
---|
34 | } |
---|
35 | |
---|
36 | /*PAGE |
---|
37 | * |
---|
38 | * _Thread_Is_executing |
---|
39 | * |
---|
40 | * DESCRIPTION: |
---|
41 | * |
---|
42 | * This function returns TRUE if the_thread is the currently executing |
---|
43 | * thread, and FALSE otherwise. |
---|
44 | */ |
---|
45 | |
---|
46 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing ( |
---|
47 | Thread_Control *the_thread |
---|
48 | ) |
---|
49 | { |
---|
50 | return ( the_thread == _Thread_Executing ); |
---|
51 | } |
---|
52 | |
---|
53 | /*PAGE |
---|
54 | * |
---|
55 | * _Thread_Is_heir |
---|
56 | * |
---|
57 | * DESCRIPTION: |
---|
58 | * |
---|
59 | * This function returns TRUE if the_thread is the heir |
---|
60 | * thread, and FALSE otherwise. |
---|
61 | */ |
---|
62 | |
---|
63 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_heir ( |
---|
64 | Thread_Control *the_thread |
---|
65 | ) |
---|
66 | { |
---|
67 | return ( the_thread == _Thread_Heir ); |
---|
68 | } |
---|
69 | |
---|
70 | /*PAGE |
---|
71 | * |
---|
72 | * _Thread_Is_executing_also_the_heir |
---|
73 | * |
---|
74 | * DESCRIPTION: |
---|
75 | * |
---|
76 | * This function returns TRUE if the currently executing thread |
---|
77 | * is also the heir thread, and FALSE otherwise. |
---|
78 | */ |
---|
79 | |
---|
80 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing_also_the_heir( void ) |
---|
81 | { |
---|
82 | return ( _Thread_Executing == _Thread_Heir ); |
---|
83 | } |
---|
84 | |
---|
85 | /*PAGE |
---|
86 | * |
---|
87 | * _Thread_Resume |
---|
88 | * |
---|
89 | * DESCRIPTION: |
---|
90 | * |
---|
91 | * This routine clears the SUSPENDED state for the_thread. It performs |
---|
92 | * any necessary scheduling operations including the selection of |
---|
93 | * a new heir thread. |
---|
94 | */ |
---|
95 | |
---|
96 | RTEMS_INLINE_ROUTINE void _Thread_Resume ( |
---|
97 | Thread_Control *the_thread |
---|
98 | ) |
---|
99 | { |
---|
100 | _Thread_Clear_state( the_thread, STATES_SUSPENDED ); |
---|
101 | } |
---|
102 | |
---|
103 | /*PAGE |
---|
104 | * |
---|
105 | * _Thread_Unblock |
---|
106 | * |
---|
107 | * DESCRIPTION: |
---|
108 | * |
---|
109 | * This routine clears any blocking state for the_thread. It performs |
---|
110 | * any necessary scheduling operations including the selection of |
---|
111 | * a new heir thread. |
---|
112 | */ |
---|
113 | |
---|
114 | RTEMS_INLINE_ROUTINE void _Thread_Unblock ( |
---|
115 | Thread_Control *the_thread |
---|
116 | ) |
---|
117 | { |
---|
118 | _Thread_Clear_state( the_thread, STATES_BLOCKED ); |
---|
119 | } |
---|
120 | |
---|
121 | /*PAGE |
---|
122 | * |
---|
123 | * _Thread_Restart_self |
---|
124 | * |
---|
125 | * DESCRIPTION: |
---|
126 | * |
---|
127 | * This routine resets the current context of the calling thread |
---|
128 | * to that of its initial state. |
---|
129 | */ |
---|
130 | |
---|
131 | RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void ) |
---|
132 | { |
---|
133 | if ( _Thread_Executing->fp_context != NULL ) |
---|
134 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
135 | |
---|
136 | _CPU_Context_Restart_self( &_Thread_Executing->Registers ); |
---|
137 | } |
---|
138 | |
---|
139 | /*PAGE |
---|
140 | * |
---|
141 | * _Thread_Calculate_heir |
---|
142 | * |
---|
143 | * DESCRIPTION: |
---|
144 | * |
---|
145 | * This function returns a pointer to the highest priority |
---|
146 | * ready thread. |
---|
147 | */ |
---|
148 | |
---|
149 | RTEMS_INLINE_ROUTINE void _Thread_Calculate_heir( void ) |
---|
150 | { |
---|
151 | _Thread_Heir = (Thread_Control *) |
---|
152 | _Thread_Ready_chain[ _Priority_Get_highest() ].first; |
---|
153 | } |
---|
154 | |
---|
155 | /*PAGE |
---|
156 | * |
---|
157 | * _Thread_Is_allocated_fp |
---|
158 | * |
---|
159 | * DESCRIPTION: |
---|
160 | * |
---|
161 | * This function returns TRUE if the floating point context of |
---|
162 | * the_thread is currently loaded in the floating point unit, and |
---|
163 | * FALSE otherwise. |
---|
164 | */ |
---|
165 | |
---|
166 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_allocated_fp ( |
---|
167 | Thread_Control *the_thread |
---|
168 | ) |
---|
169 | { |
---|
170 | return ( the_thread == _Thread_Allocated_fp ); |
---|
171 | } |
---|
172 | |
---|
173 | /*PAGE |
---|
174 | * |
---|
175 | * _Thread_Deallocate_fp |
---|
176 | * |
---|
177 | * DESCRIPTION: |
---|
178 | * |
---|
179 | * This routine is invoked when the currently loaded floating |
---|
180 | * point context is now longer associated with an active thread. |
---|
181 | */ |
---|
182 | |
---|
183 | RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void ) |
---|
184 | { |
---|
185 | _Thread_Allocated_fp = NULL; |
---|
186 | } |
---|
187 | |
---|
188 | /*PAGE |
---|
189 | * |
---|
190 | * _Thread_Disable_dispatch |
---|
191 | * |
---|
192 | * DESCRIPTION: |
---|
193 | * |
---|
194 | * This routine prevents dispatching. |
---|
195 | */ |
---|
196 | |
---|
197 | RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void ) |
---|
198 | { |
---|
199 | _Thread_Dispatch_disable_level += 1; |
---|
200 | } |
---|
201 | |
---|
202 | /*PAGE |
---|
203 | * |
---|
204 | * _Thread_Enable_dispatch |
---|
205 | * |
---|
206 | * DESCRIPTION: |
---|
207 | * |
---|
208 | * This routine allows dispatching to occur again. If this is |
---|
209 | * the outer most dispatching critical section, then a dispatching |
---|
210 | * operation will be performed and, if necessary, control of the |
---|
211 | * processor will be transferred to the heir thread. |
---|
212 | */ |
---|
213 | |
---|
214 | #if ( CPU_INLINE_ENABLE_DISPATCH == TRUE ) |
---|
215 | RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch() |
---|
216 | { |
---|
217 | if ( (--_Thread_Dispatch_disable_level) == 0 ) |
---|
218 | _Thread_Dispatch(); |
---|
219 | } |
---|
220 | #endif |
---|
221 | |
---|
222 | #if ( CPU_INLINE_ENABLE_DISPATCH == FALSE ) |
---|
223 | void _Thread_Enable_dispatch( void ); |
---|
224 | #endif |
---|
225 | |
---|
226 | /*PAGE |
---|
227 | * |
---|
228 | * _Thread_Unnest_dispatch |
---|
229 | * |
---|
230 | * DESCRIPTION: |
---|
231 | * |
---|
232 | * This routine allows dispatching to occur again. However, |
---|
233 | * no dispatching operation is performed even if this is the outer |
---|
234 | * most dispatching critical section. |
---|
235 | */ |
---|
236 | |
---|
237 | RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void ) |
---|
238 | { |
---|
239 | _Thread_Dispatch_disable_level -= 1; |
---|
240 | } |
---|
241 | |
---|
242 | /*PAGE |
---|
243 | * |
---|
244 | * _Thread_Is_dispatching_enabled |
---|
245 | * |
---|
246 | * DESCRIPTION: |
---|
247 | * |
---|
248 | * This function returns TRUE if dispatching is disabled, and FALSE |
---|
249 | * otherwise. |
---|
250 | */ |
---|
251 | |
---|
252 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_dispatching_enabled( void ) |
---|
253 | { |
---|
254 | return ( _Thread_Dispatch_disable_level == 0 ); |
---|
255 | } |
---|
256 | |
---|
257 | /*PAGE |
---|
258 | * |
---|
259 | * _Thread_Is_context_switch_necessary |
---|
260 | * |
---|
261 | * DESCRIPTION: |
---|
262 | * |
---|
263 | * This function returns TRUE if dispatching is disabled, and FALSE |
---|
264 | * otherwise. |
---|
265 | */ |
---|
266 | |
---|
267 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_context_switch_necessary( void ) |
---|
268 | { |
---|
269 | return ( _Context_Switch_necessary ); |
---|
270 | } |
---|
271 | |
---|
272 | /*PAGE |
---|
273 | * |
---|
274 | * _Thread_Dispatch_initialization |
---|
275 | * |
---|
276 | * DESCRIPTION: |
---|
277 | * |
---|
278 | * This routine initializes the thread dispatching subsystem. |
---|
279 | */ |
---|
280 | |
---|
281 | RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void ) |
---|
282 | { |
---|
283 | _Thread_Dispatch_disable_level = 1; |
---|
284 | } |
---|
285 | |
---|
286 | /*PAGE |
---|
287 | * |
---|
288 | * _Thread_Is_null |
---|
289 | * |
---|
290 | * DESCRIPTION: |
---|
291 | * |
---|
292 | * This function returns TRUE if the_thread is NULL and FALSE otherwise. |
---|
293 | */ |
---|
294 | |
---|
295 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_null ( |
---|
296 | Thread_Control *the_thread |
---|
297 | ) |
---|
298 | { |
---|
299 | return ( the_thread == NULL ); |
---|
300 | } |
---|
301 | |
---|
302 | /*PAGE |
---|
303 | * |
---|
304 | * _Thread_Get |
---|
305 | * |
---|
306 | * DESCRIPTION: |
---|
307 | * |
---|
308 | * This function maps thread IDs to thread control |
---|
309 | * blocks. If ID corresponds to a local thread, then it |
---|
310 | * returns the_thread control pointer which maps to ID |
---|
311 | * and location is set to OBJECTS_LOCAL. If the thread ID is |
---|
312 | * global and resides on a remote node, then location is set |
---|
313 | * to OBJECTS_REMOTE, and the_thread is undefined. |
---|
314 | * Otherwise, location is set to OBJECTS_ERROR and |
---|
315 | * the_thread is undefined. |
---|
316 | * |
---|
317 | * NOTE: XXX... This routine may be able to be optimized. |
---|
318 | */ |
---|
319 | |
---|
320 | RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Get ( |
---|
321 | Objects_Id id, |
---|
322 | Objects_Locations *location |
---|
323 | ) |
---|
324 | { |
---|
325 | Objects_Classes the_class; |
---|
326 | Objects_Information *information; |
---|
327 | Thread_Control *tp = (Thread_Control *) 0; |
---|
328 | |
---|
329 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { |
---|
330 | _Thread_Disable_dispatch(); |
---|
331 | *location = OBJECTS_LOCAL; |
---|
332 | tp = _Thread_Executing; |
---|
333 | goto done; |
---|
334 | } |
---|
335 | |
---|
336 | the_class = _Objects_Get_class( id ); |
---|
337 | |
---|
338 | if ( the_class > OBJECTS_CLASSES_LAST ) { |
---|
339 | *location = OBJECTS_ERROR; |
---|
340 | goto done; |
---|
341 | } |
---|
342 | |
---|
343 | information = _Objects_Information_table[ the_class ]; |
---|
344 | |
---|
345 | if ( !information || !information->is_thread ) { |
---|
346 | *location = OBJECTS_ERROR; |
---|
347 | goto done; |
---|
348 | } |
---|
349 | |
---|
350 | tp = (Thread_Control *) _Objects_Get( information, id, location ); |
---|
351 | |
---|
352 | done: |
---|
353 | return tp; |
---|
354 | } |
---|
355 | |
---|
356 | |
---|
357 | /* |
---|
358 | * _Thread_Is_proxy_blocking |
---|
359 | * |
---|
360 | * DESCRIPTION: |
---|
361 | * |
---|
362 | * This function returns TRUE if the status code is equal to the |
---|
363 | * status which indicates that a proxy is blocking, and FALSE otherwise. |
---|
364 | */ |
---|
365 | |
---|
366 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_proxy_blocking ( |
---|
367 | unsigned32 code |
---|
368 | ) |
---|
369 | { |
---|
370 | return (code == THREAD_STATUS_PROXY_BLOCKING); |
---|
371 | } |
---|
372 | |
---|
373 | /*PAGE |
---|
374 | * |
---|
375 | * _Thread_Internal_allocate |
---|
376 | * |
---|
377 | * DESCRIPTION: |
---|
378 | * |
---|
379 | * This routine allocates an internal thread. |
---|
380 | */ |
---|
381 | |
---|
382 | RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void ) |
---|
383 | { |
---|
384 | return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information ); |
---|
385 | } |
---|
386 | |
---|
387 | /*PAGE |
---|
388 | * |
---|
389 | * _Thread_Internal_free |
---|
390 | * |
---|
391 | * DESCRIPTION: |
---|
392 | * |
---|
393 | * This routine frees an internal thread. |
---|
394 | */ |
---|
395 | |
---|
396 | RTEMS_INLINE_ROUTINE void _Thread_Internal_free ( |
---|
397 | Thread_Control *the_task |
---|
398 | ) |
---|
399 | { |
---|
400 | _Objects_Free( &_Thread_Internal_information, &the_task->Object ); |
---|
401 | } |
---|
402 | |
---|
403 | #endif |
---|
404 | /* end of include file */ |
---|