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-2008. |
---|
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_H |
---|
20 | # error "Never use <rtems/score/thread.inl> directly; include <rtems/score/thread.h> instead." |
---|
21 | #endif |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_THREAD_INL |
---|
24 | #define _RTEMS_SCORE_THREAD_INL |
---|
25 | |
---|
26 | #include <rtems/score/sysstate.h> |
---|
27 | #include <rtems/score/context.h> |
---|
28 | |
---|
29 | /** |
---|
30 | * @addtogroup ScoreThread |
---|
31 | * @{ |
---|
32 | */ |
---|
33 | |
---|
34 | /** |
---|
35 | * This routine halts multitasking and returns control to |
---|
36 | * the "thread" (i.e. the BSP) which initially invoked the |
---|
37 | * routine which initialized the system. |
---|
38 | */ |
---|
39 | |
---|
40 | RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void ) |
---|
41 | { |
---|
42 | Context_Control context_area; |
---|
43 | Context_Control *context_p = &context_area; |
---|
44 | |
---|
45 | if ( _System_state_Is_up(_System_state_Get ()) ) |
---|
46 | context_p = &_Thread_Executing->Registers; |
---|
47 | |
---|
48 | /* |
---|
49 | * This may look a bit of an odd but _Context_Restart_self is just |
---|
50 | * a very careful restore of a specific context which ensures that |
---|
51 | * if we were running within the same context, it would work. |
---|
52 | * |
---|
53 | * And we will not return to this thread, so there is no point of |
---|
54 | * saving the context. |
---|
55 | */ |
---|
56 | _Context_Restart_self( &_Thread_BSP_context ); |
---|
57 | |
---|
58 | /*************************************************************** |
---|
59 | *************************************************************** |
---|
60 | * SYSTEM SHUTS DOWN!!! WE DO NOT RETURN TO THIS POINT!!! * |
---|
61 | *************************************************************** |
---|
62 | *************************************************************** |
---|
63 | */ |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * This function returns true if the_thread is the currently executing |
---|
68 | * thread, and false otherwise. |
---|
69 | */ |
---|
70 | |
---|
71 | RTEMS_INLINE_ROUTINE bool _Thread_Is_executing ( |
---|
72 | const Thread_Control *the_thread |
---|
73 | ) |
---|
74 | { |
---|
75 | return ( the_thread == _Thread_Executing ); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * This function returns true if the_thread is the heir |
---|
80 | * thread, and false otherwise. |
---|
81 | */ |
---|
82 | |
---|
83 | RTEMS_INLINE_ROUTINE bool _Thread_Is_heir ( |
---|
84 | const Thread_Control *the_thread |
---|
85 | ) |
---|
86 | { |
---|
87 | return ( the_thread == _Thread_Heir ); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * This function returns true if the currently executing thread |
---|
92 | * is also the heir thread, and false otherwise. |
---|
93 | */ |
---|
94 | |
---|
95 | RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_also_the_heir( void ) |
---|
96 | { |
---|
97 | return ( _Thread_Executing == _Thread_Heir ); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * This routine clears any blocking state for the_thread. It performs |
---|
102 | * any necessary scheduling operations including the selection of |
---|
103 | * a new heir thread. |
---|
104 | */ |
---|
105 | |
---|
106 | RTEMS_INLINE_ROUTINE void _Thread_Unblock ( |
---|
107 | Thread_Control *the_thread |
---|
108 | ) |
---|
109 | { |
---|
110 | _Thread_Clear_state( the_thread, STATES_BLOCKED ); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * This routine resets the current context of the calling thread |
---|
115 | * to that of its initial state. |
---|
116 | */ |
---|
117 | |
---|
118 | RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void ) |
---|
119 | { |
---|
120 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
121 | if ( _Thread_Executing->fp_context != NULL ) |
---|
122 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
123 | #endif |
---|
124 | |
---|
125 | _CPU_Context_Restart_self( &_Thread_Executing->Registers ); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * This function returns a pointer to the highest priority |
---|
130 | * ready thread. |
---|
131 | */ |
---|
132 | |
---|
133 | RTEMS_INLINE_ROUTINE void _Thread_Calculate_heir( void ) |
---|
134 | { |
---|
135 | _Thread_Heir = (Thread_Control *) |
---|
136 | _Thread_Ready_chain[ _Priority_Get_highest() ].first; |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * This function returns true if the floating point context of |
---|
141 | * the_thread is currently loaded in the floating point unit, and |
---|
142 | * false otherwise. |
---|
143 | */ |
---|
144 | |
---|
145 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
146 | RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp ( |
---|
147 | const Thread_Control *the_thread |
---|
148 | ) |
---|
149 | { |
---|
150 | return ( the_thread == _Thread_Allocated_fp ); |
---|
151 | } |
---|
152 | #endif |
---|
153 | |
---|
154 | /** |
---|
155 | * This routine is invoked when the currently loaded floating |
---|
156 | * point context is now longer associated with an active thread. |
---|
157 | */ |
---|
158 | |
---|
159 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
160 | RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void ) |
---|
161 | { |
---|
162 | _Thread_Allocated_fp = NULL; |
---|
163 | } |
---|
164 | #endif |
---|
165 | |
---|
166 | /** |
---|
167 | * This routine prevents dispatching. |
---|
168 | */ |
---|
169 | |
---|
170 | #if defined(RTEMS_HEAVY_STACK_DEBUG) || defined(RTEMS_HEAVY_MALLOC_DEBUG) |
---|
171 | #include <rtems/bspIo.h> |
---|
172 | #include <rtems/fatal.h> |
---|
173 | #include <rtems/stackchk.h> |
---|
174 | #include <rtems/score/sysstate.h> |
---|
175 | #include <rtems/score/heap.h> |
---|
176 | |
---|
177 | /* |
---|
178 | * This is currently not defined in any .h file, so we have to |
---|
179 | * extern it here. |
---|
180 | */ |
---|
181 | extern Heap_Control *RTEMS_Malloc_Heap; |
---|
182 | #endif |
---|
183 | |
---|
184 | RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void ) |
---|
185 | { |
---|
186 | /* |
---|
187 | * This check is very brutal to system performance but is very helpful |
---|
188 | * at finding blown stack problems. If you have a stack problem and |
---|
189 | * need help finding it, then uncomment this code. Every system |
---|
190 | * call will check the stack and since mutexes are used frequently |
---|
191 | * in most systems, you might get lucky. |
---|
192 | */ |
---|
193 | #if defined(RTEMS_HEAVY_STACK_DEBUG) |
---|
194 | if (_System_state_Is_up(_System_state_Get()) && (_ISR_Nest_level == 0)) { |
---|
195 | if ( rtems_stack_checker_is_blown() ) { |
---|
196 | printk( "Stack blown!!\n" ); |
---|
197 | rtems_fatal_error_occurred( 99 ); |
---|
198 | } |
---|
199 | } |
---|
200 | #endif |
---|
201 | |
---|
202 | _Thread_Dispatch_disable_level += 1; |
---|
203 | RTEMS_COMPILER_MEMORY_BARRIER(); |
---|
204 | |
---|
205 | /* |
---|
206 | * This check is even more brutal than the other one. This enables |
---|
207 | * malloc heap integrity checking upon entry to every system call. |
---|
208 | */ |
---|
209 | #if defined(RTEMS_HEAVY_MALLOC_DEBUG) |
---|
210 | if ( _Thread_Dispatch_disable_level == 1 ) { |
---|
211 | _Heap_Walk( RTEMS_Malloc_Heap,99, false ); |
---|
212 | } |
---|
213 | #endif |
---|
214 | } |
---|
215 | |
---|
216 | /** |
---|
217 | * This routine allows dispatching to occur again. If this is |
---|
218 | * the outer most dispatching critical section, then a dispatching |
---|
219 | * operation will be performed and, if necessary, control of the |
---|
220 | * processor will be transferred to the heir thread. |
---|
221 | */ |
---|
222 | |
---|
223 | #if ( (defined(CPU_INLINE_ENABLE_DISPATCH) && \ |
---|
224 | (CPU_INLINE_ENABLE_DISPATCH == FALSE)) || \ |
---|
225 | (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1) ) |
---|
226 | void _Thread_Enable_dispatch( void ); |
---|
227 | #else |
---|
228 | /* inlining of enable dispatching must be true */ |
---|
229 | RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch( void ) |
---|
230 | { |
---|
231 | RTEMS_COMPILER_MEMORY_BARRIER(); |
---|
232 | if ( (--_Thread_Dispatch_disable_level) == 0 ) |
---|
233 | _Thread_Dispatch(); |
---|
234 | } |
---|
235 | #endif |
---|
236 | |
---|
237 | |
---|
238 | /** |
---|
239 | * This routine allows dispatching to occur again. However, |
---|
240 | * no dispatching operation is performed even if this is the outer |
---|
241 | * most dispatching critical section. |
---|
242 | */ |
---|
243 | |
---|
244 | RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void ) |
---|
245 | { |
---|
246 | RTEMS_COMPILER_MEMORY_BARRIER(); |
---|
247 | _Thread_Dispatch_disable_level -= 1; |
---|
248 | } |
---|
249 | |
---|
250 | /** |
---|
251 | * This function returns true if dispatching is disabled, and false |
---|
252 | * otherwise. |
---|
253 | */ |
---|
254 | |
---|
255 | RTEMS_INLINE_ROUTINE bool _Thread_Is_dispatching_enabled( void ) |
---|
256 | { |
---|
257 | return ( _Thread_Dispatch_disable_level == 0 ); |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | * This function returns true if dispatching is disabled, and false |
---|
262 | * otherwise. |
---|
263 | */ |
---|
264 | |
---|
265 | RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary( void ) |
---|
266 | { |
---|
267 | return ( _Context_Switch_necessary ); |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * This routine initializes the thread dispatching subsystem. |
---|
272 | */ |
---|
273 | |
---|
274 | RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void ) |
---|
275 | { |
---|
276 | _Thread_Dispatch_disable_level = 1; |
---|
277 | } |
---|
278 | |
---|
279 | /** |
---|
280 | * This function returns true if the_thread is NULL and false otherwise. |
---|
281 | */ |
---|
282 | |
---|
283 | RTEMS_INLINE_ROUTINE bool _Thread_Is_null ( |
---|
284 | const Thread_Control *the_thread |
---|
285 | ) |
---|
286 | { |
---|
287 | return ( the_thread == NULL ); |
---|
288 | } |
---|
289 | |
---|
290 | /** @brief _Thread_Is_proxy_blocking |
---|
291 | * |
---|
292 | * status which indicates that a proxy is blocking, and false otherwise. |
---|
293 | */ |
---|
294 | RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking ( |
---|
295 | uint32_t code |
---|
296 | ) |
---|
297 | { |
---|
298 | return (code == THREAD_STATUS_PROXY_BLOCKING); |
---|
299 | } |
---|
300 | |
---|
301 | /** |
---|
302 | * This routine allocates an internal thread. |
---|
303 | */ |
---|
304 | |
---|
305 | RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void ) |
---|
306 | { |
---|
307 | return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information ); |
---|
308 | } |
---|
309 | |
---|
310 | /** |
---|
311 | * This routine frees an internal thread. |
---|
312 | */ |
---|
313 | |
---|
314 | RTEMS_INLINE_ROUTINE void _Thread_Internal_free ( |
---|
315 | Thread_Control *the_task |
---|
316 | ) |
---|
317 | { |
---|
318 | _Objects_Free( &_Thread_Internal_information, &the_task->Object ); |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * This routine returns the C library re-enterant pointer. |
---|
323 | */ |
---|
324 | |
---|
325 | RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void ) |
---|
326 | { |
---|
327 | return _Thread_libc_reent; |
---|
328 | } |
---|
329 | |
---|
330 | /** |
---|
331 | * This routine set the C library re-enterant pointer. |
---|
332 | */ |
---|
333 | |
---|
334 | RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent ( |
---|
335 | struct _reent **libc_reent |
---|
336 | ) |
---|
337 | { |
---|
338 | _Thread_libc_reent = libc_reent; |
---|
339 | } |
---|
340 | |
---|
341 | /**@}*/ |
---|
342 | |
---|
343 | #endif |
---|
344 | /* end of include file */ |
---|