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