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