1 | /** |
---|
2 | * @file rtems/score/thread.inl |
---|
3 | * |
---|
4 | * This file contains the macro implementation of the inlined |
---|
5 | * routines from the Thread handler. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2006. |
---|
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.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_THREAD_INL |
---|
20 | #define _RTEMS_SCORE_THREAD_INL |
---|
21 | |
---|
22 | /** |
---|
23 | * @addtogroup ScoreThread |
---|
24 | * @{ |
---|
25 | */ |
---|
26 | |
---|
27 | /** |
---|
28 | * This routine halts multitasking and returns control to |
---|
29 | * the "thread" (i.e. the BSP) which initially invoked the |
---|
30 | * routine which initialized the system. |
---|
31 | */ |
---|
32 | |
---|
33 | RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void ) |
---|
34 | { |
---|
35 | _Context_Switch( &_Thread_Executing->Registers, &_Thread_BSP_context ); |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * This function returns TRUE if the_thread is the currently executing |
---|
40 | * thread, and FALSE otherwise. |
---|
41 | */ |
---|
42 | |
---|
43 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing ( |
---|
44 | Thread_Control *the_thread |
---|
45 | ) |
---|
46 | { |
---|
47 | return ( the_thread == _Thread_Executing ); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * This function returns TRUE if the_thread is the heir |
---|
52 | * thread, and FALSE otherwise. |
---|
53 | */ |
---|
54 | |
---|
55 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_heir ( |
---|
56 | Thread_Control *the_thread |
---|
57 | ) |
---|
58 | { |
---|
59 | return ( the_thread == _Thread_Heir ); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * This function returns TRUE if the currently executing thread |
---|
64 | * is also the heir thread, and FALSE otherwise. |
---|
65 | */ |
---|
66 | |
---|
67 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing_also_the_heir( void ) |
---|
68 | { |
---|
69 | return ( _Thread_Executing == _Thread_Heir ); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * This routine clears any blocking state for the_thread. It performs |
---|
74 | * any necessary scheduling operations including the selection of |
---|
75 | * a new heir thread. |
---|
76 | */ |
---|
77 | |
---|
78 | RTEMS_INLINE_ROUTINE void _Thread_Unblock ( |
---|
79 | Thread_Control *the_thread |
---|
80 | ) |
---|
81 | { |
---|
82 | _Thread_Clear_state( the_thread, STATES_BLOCKED ); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * This routine resets the current context of the calling thread |
---|
87 | * to that of its initial state. |
---|
88 | */ |
---|
89 | |
---|
90 | RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void ) |
---|
91 | { |
---|
92 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
93 | if ( _Thread_Executing->fp_context != NULL ) |
---|
94 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
95 | #endif |
---|
96 | |
---|
97 | _CPU_Context_Restart_self( &_Thread_Executing->Registers ); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * This function returns a pointer to the highest priority |
---|
102 | * ready thread. |
---|
103 | */ |
---|
104 | |
---|
105 | RTEMS_INLINE_ROUTINE void _Thread_Calculate_heir( void ) |
---|
106 | { |
---|
107 | _Thread_Heir = (Thread_Control *) |
---|
108 | _Thread_Ready_chain[ _Priority_Get_highest() ].first; |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * This function returns TRUE if the floating point context of |
---|
113 | * the_thread is currently loaded in the floating point unit, and |
---|
114 | * FALSE otherwise. |
---|
115 | */ |
---|
116 | |
---|
117 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
118 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_allocated_fp ( |
---|
119 | Thread_Control *the_thread |
---|
120 | ) |
---|
121 | { |
---|
122 | return ( the_thread == _Thread_Allocated_fp ); |
---|
123 | } |
---|
124 | #endif |
---|
125 | |
---|
126 | /** |
---|
127 | * This routine is invoked when the currently loaded floating |
---|
128 | * point context is now longer associated with an active thread. |
---|
129 | */ |
---|
130 | |
---|
131 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
132 | RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void ) |
---|
133 | { |
---|
134 | _Thread_Allocated_fp = NULL; |
---|
135 | } |
---|
136 | #endif |
---|
137 | |
---|
138 | /** |
---|
139 | * This routine prevents dispatching. |
---|
140 | */ |
---|
141 | |
---|
142 | RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void ) |
---|
143 | { |
---|
144 | _Thread_Dispatch_disable_level += 1; |
---|
145 | RTEMS_COMPILER_MEMORY_BARRIER(); |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * This routine allows dispatching to occur again. If this is |
---|
150 | * the outer most dispatching critical section, then a dispatching |
---|
151 | * operation will be performed and, if necessary, control of the |
---|
152 | * processor will be transferred to the heir thread. |
---|
153 | */ |
---|
154 | |
---|
155 | #if ( CPU_INLINE_ENABLE_DISPATCH == TRUE ) |
---|
156 | RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch() |
---|
157 | { |
---|
158 | RTEMS_COMPILER_MEMORY_BARRIER(); |
---|
159 | if ( (--_Thread_Dispatch_disable_level) == 0 ) |
---|
160 | _Thread_Dispatch(); |
---|
161 | } |
---|
162 | #endif |
---|
163 | |
---|
164 | #if ( CPU_INLINE_ENABLE_DISPATCH == FALSE ) |
---|
165 | void _Thread_Enable_dispatch( void ); |
---|
166 | #endif |
---|
167 | |
---|
168 | /** |
---|
169 | * This routine allows dispatching to occur again. However, |
---|
170 | * no dispatching operation is performed even if this is the outer |
---|
171 | * most dispatching critical section. |
---|
172 | */ |
---|
173 | |
---|
174 | RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void ) |
---|
175 | { |
---|
176 | RTEMS_COMPILER_MEMORY_BARRIER(); |
---|
177 | _Thread_Dispatch_disable_level -= 1; |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * This function returns TRUE if dispatching is disabled, and FALSE |
---|
182 | * otherwise. |
---|
183 | */ |
---|
184 | |
---|
185 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_dispatching_enabled( void ) |
---|
186 | { |
---|
187 | return ( _Thread_Dispatch_disable_level == 0 ); |
---|
188 | } |
---|
189 | |
---|
190 | /** |
---|
191 | * This function returns TRUE if dispatching is disabled, and FALSE |
---|
192 | * otherwise. |
---|
193 | */ |
---|
194 | |
---|
195 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_context_switch_necessary( void ) |
---|
196 | { |
---|
197 | return ( _Context_Switch_necessary ); |
---|
198 | } |
---|
199 | |
---|
200 | /** |
---|
201 | * This routine initializes the thread dispatching subsystem. |
---|
202 | */ |
---|
203 | |
---|
204 | RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void ) |
---|
205 | { |
---|
206 | _Thread_Dispatch_disable_level = 1; |
---|
207 | } |
---|
208 | |
---|
209 | /** |
---|
210 | * This function returns TRUE if the_thread is NULL and FALSE otherwise. |
---|
211 | */ |
---|
212 | |
---|
213 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_null ( |
---|
214 | Thread_Control *the_thread |
---|
215 | ) |
---|
216 | { |
---|
217 | return ( the_thread == NULL ); |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | * This function maps thread IDs to thread control |
---|
222 | * blocks. If ID corresponds to a local thread, then it |
---|
223 | * returns the_thread control pointer which maps to ID |
---|
224 | * and location is set to OBJECTS_LOCAL. If the thread ID is |
---|
225 | * global and resides on a remote node, then location is set |
---|
226 | * to OBJECTS_REMOTE, and the_thread is undefined. |
---|
227 | * Otherwise, location is set to OBJECTS_ERROR and |
---|
228 | * the_thread is undefined. |
---|
229 | * |
---|
230 | * @note The performance of many RTEMS services depends upon |
---|
231 | * the quick execution of the "good object" path in this |
---|
232 | * routine. If there is a possibility of saving a few |
---|
233 | * cycles off the execution time, this routine is worth |
---|
234 | * further optimization attention. |
---|
235 | */ |
---|
236 | |
---|
237 | RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Get ( |
---|
238 | Objects_Id id, |
---|
239 | Objects_Locations *location |
---|
240 | ) |
---|
241 | { |
---|
242 | uint32_t the_api; |
---|
243 | uint32_t the_class; |
---|
244 | Objects_Information *information; |
---|
245 | Thread_Control *tp = (Thread_Control *) 0; |
---|
246 | |
---|
247 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { |
---|
248 | _Thread_Disable_dispatch(); |
---|
249 | *location = OBJECTS_LOCAL; |
---|
250 | tp = _Thread_Executing; |
---|
251 | goto done; |
---|
252 | } |
---|
253 | |
---|
254 | the_api = _Objects_Get_API( id ); |
---|
255 | if ( the_api && the_api > OBJECTS_APIS_LAST ) { |
---|
256 | *location = OBJECTS_ERROR; |
---|
257 | goto done; |
---|
258 | } |
---|
259 | |
---|
260 | the_class = _Objects_Get_class( id ); |
---|
261 | if ( the_class != 1 ) { /* threads are always first class :) */ |
---|
262 | *location = OBJECTS_ERROR; |
---|
263 | goto done; |
---|
264 | } |
---|
265 | |
---|
266 | information = _Objects_Information_table[ the_api ][ the_class ]; |
---|
267 | |
---|
268 | if ( !information ) { |
---|
269 | *location = OBJECTS_ERROR; |
---|
270 | goto done; |
---|
271 | } |
---|
272 | |
---|
273 | tp = (Thread_Control *) _Objects_Get( information, id, location ); |
---|
274 | |
---|
275 | done: |
---|
276 | return tp; |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | /** @brief _Thread_Is_proxy_blocking |
---|
281 | * |
---|
282 | * status which indicates that a proxy is blocking, and FALSE otherwise. |
---|
283 | */ |
---|
284 | RTEMS_INLINE_ROUTINE boolean _Thread_Is_proxy_blocking ( |
---|
285 | uint32_t code |
---|
286 | ) |
---|
287 | { |
---|
288 | return (code == THREAD_STATUS_PROXY_BLOCKING); |
---|
289 | } |
---|
290 | |
---|
291 | /** |
---|
292 | * This routine allocates an internal thread. |
---|
293 | */ |
---|
294 | |
---|
295 | RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void ) |
---|
296 | { |
---|
297 | return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information ); |
---|
298 | } |
---|
299 | |
---|
300 | /** |
---|
301 | * This routine frees an internal thread. |
---|
302 | */ |
---|
303 | |
---|
304 | RTEMS_INLINE_ROUTINE void _Thread_Internal_free ( |
---|
305 | Thread_Control *the_task |
---|
306 | ) |
---|
307 | { |
---|
308 | _Objects_Free( &_Thread_Internal_information, &the_task->Object ); |
---|
309 | } |
---|
310 | |
---|
311 | /** |
---|
312 | * This routine returns the C library re-enterant pointer. |
---|
313 | */ |
---|
314 | |
---|
315 | RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void ) |
---|
316 | { |
---|
317 | return _Thread_libc_reent; |
---|
318 | } |
---|
319 | |
---|
320 | /** |
---|
321 | * This routine set the C library re-enterant pointer. |
---|
322 | */ |
---|
323 | |
---|
324 | RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent ( |
---|
325 | struct _reent **libc_reent |
---|
326 | ) |
---|
327 | { |
---|
328 | _Thread_libc_reent = libc_reent; |
---|
329 | } |
---|
330 | |
---|
331 | /**@}*/ |
---|
332 | |
---|
333 | #endif |
---|
334 | /* end of include file */ |
---|