1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines Associated with Thread State Information |
---|
5 | * |
---|
6 | * This file contains the static inline implementation of the inlined |
---|
7 | * routines associated with thread state information. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2012. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_STATESIMPL_H |
---|
20 | #define _RTEMS_SCORE_STATESIMPL_H |
---|
21 | |
---|
22 | #include <rtems/score/states.h> |
---|
23 | #include <rtems/score/basedefs.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @addtogroup ScoreStates |
---|
31 | */ |
---|
32 | /**@{**/ |
---|
33 | |
---|
34 | /* |
---|
35 | * The following constants define the individual states which may be |
---|
36 | * be used to compose and manipulate a thread's state. |
---|
37 | */ |
---|
38 | |
---|
39 | /** This macro corresponds to a task being ready. */ |
---|
40 | #define STATES_READY 0x00000000 |
---|
41 | /** This macro corresponds to a task being created but not yet started. */ |
---|
42 | #define STATES_DORMANT 0x00000001 |
---|
43 | /** This macro corresponds to a task being suspended. */ |
---|
44 | #define STATES_SUSPENDED 0x00000002 |
---|
45 | /** This macro corresponds to a task which is waiting for a timeout. */ |
---|
46 | #define STATES_DELAYING 0x00000008 |
---|
47 | /** This macro corresponds to a task waiting until a specific TOD. */ |
---|
48 | #define STATES_WAITING_FOR_TIME 0x00000010 |
---|
49 | /** This macro corresponds to a task waiting for a fixed size segment. */ |
---|
50 | #define STATES_WAITING_FOR_SEGMENT 0x00000040 |
---|
51 | /** This macro corresponds to a task waiting for a message. */ |
---|
52 | #define STATES_WAITING_FOR_MESSAGE 0x00000080 |
---|
53 | /** This macro corresponds to a task waiting for an event. */ |
---|
54 | #define STATES_WAITING_FOR_EVENT 0x00000100 |
---|
55 | /** This macro corresponds to a task waiting for a semaphore. */ |
---|
56 | #define STATES_WAITING_FOR_SEMAPHORE 0x00000200 |
---|
57 | /** This macro corresponds to a task waiting for a mutex. */ |
---|
58 | #define STATES_WAITING_FOR_MUTEX 0x00000400 |
---|
59 | /** This macro corresponds to a task waiting for a condition variable. */ |
---|
60 | #define STATES_WAITING_FOR_CONDITION_VARIABLE 0x00000800 |
---|
61 | /** This macro corresponds to a task waiting for a join while exiting. */ |
---|
62 | #define STATES_WAITING_FOR_JOIN_AT_EXIT 0x00001000 |
---|
63 | /** This macro corresponds to a task waiting for a reply to an MPCI request. */ |
---|
64 | #define STATES_WAITING_FOR_RPC_REPLY 0x00002000 |
---|
65 | /** This macro corresponds to a task waiting for a period. */ |
---|
66 | #define STATES_WAITING_FOR_PERIOD 0x00004000 |
---|
67 | /** This macro corresponds to a task waiting for a signal. */ |
---|
68 | #define STATES_WAITING_FOR_SIGNAL 0x00008000 |
---|
69 | /** This macro corresponds to a task waiting for a barrier. */ |
---|
70 | #define STATES_WAITING_FOR_BARRIER 0x00010000 |
---|
71 | /** This macro corresponds to a task waiting for a RWLock. */ |
---|
72 | #define STATES_WAITING_FOR_RWLOCK 0x00020000 |
---|
73 | /** This macro corresponds to a task waiting for a system event. */ |
---|
74 | #define STATES_WAITING_FOR_SYSTEM_EVENT 0x00040000 |
---|
75 | /** This macro corresponds to a task waiting for BSD wakeup. */ |
---|
76 | #define STATES_WAITING_FOR_BSD_WAKEUP 0x00080000 |
---|
77 | /** This macro corresponds to a task being held by the debugger. */ |
---|
78 | #define STATES_DEBUGGER 0x00100000 |
---|
79 | /** This macro corresponds to a task being a zombie. */ |
---|
80 | #define STATES_ZOMBIE 0x00200000 |
---|
81 | /** This macro corresponds to a task those life is changing. */ |
---|
82 | #define STATES_LIFE_IS_CHANGING 0x00800000 |
---|
83 | /** This macro corresponds to a task waiting for a join. */ |
---|
84 | #define STATES_WAITING_FOR_JOIN 0x01000000 |
---|
85 | /** This macro corresponds to a task waiting for a futex. */ |
---|
86 | #define STATES_WAITING_FOR_FUTEX 0x08000000 |
---|
87 | |
---|
88 | /** This macro corresponds to a task which is in an interruptible |
---|
89 | * blocking state. |
---|
90 | */ |
---|
91 | #define STATES_INTERRUPTIBLE_BY_SIGNAL 0x10000000 |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief This macro corresponds to a task which is blocked on a thread queue |
---|
95 | * embedded in an object with an identifier. |
---|
96 | * |
---|
97 | * This thread state bit is intended to ease debugging and improve system |
---|
98 | * diagnostics, see _Thread_Wait_get_id(). |
---|
99 | */ |
---|
100 | #define STATES_THREAD_QUEUE_WITH_IDENTIFIER 0x80000000 |
---|
101 | |
---|
102 | /** This macro corresponds to a task waiting for a local object operation. */ |
---|
103 | #define STATES_LOCALLY_BLOCKED ( STATES_THREAD_QUEUE_WITH_IDENTIFIER | \ |
---|
104 | STATES_WAITING_FOR_SEGMENT | \ |
---|
105 | STATES_WAITING_FOR_MESSAGE | \ |
---|
106 | STATES_WAITING_FOR_SEMAPHORE | \ |
---|
107 | STATES_WAITING_FOR_MUTEX | \ |
---|
108 | STATES_WAITING_FOR_CONDITION_VARIABLE | \ |
---|
109 | STATES_WAITING_FOR_JOIN | \ |
---|
110 | STATES_WAITING_FOR_SIGNAL | \ |
---|
111 | STATES_WAITING_FOR_BARRIER | \ |
---|
112 | STATES_WAITING_FOR_BSD_WAKEUP | \ |
---|
113 | STATES_WAITING_FOR_FUTEX | \ |
---|
114 | STATES_WAITING_FOR_RWLOCK ) |
---|
115 | |
---|
116 | /** This macro corresponds to a task waiting which is blocked. */ |
---|
117 | #define STATES_BLOCKED ( STATES_DELAYING | \ |
---|
118 | STATES_LOCALLY_BLOCKED | \ |
---|
119 | STATES_WAITING_FOR_TIME | \ |
---|
120 | STATES_WAITING_FOR_PERIOD | \ |
---|
121 | STATES_WAITING_FOR_EVENT | \ |
---|
122 | STATES_WAITING_FOR_RPC_REPLY | \ |
---|
123 | STATES_WAITING_FOR_SYSTEM_EVENT | \ |
---|
124 | STATES_INTERRUPTIBLE_BY_SIGNAL ) |
---|
125 | |
---|
126 | /** All state bits set to one (provided for _Thread_Start()) */ |
---|
127 | #define STATES_ALL_SET 0xffffffff |
---|
128 | |
---|
129 | /** |
---|
130 | * This function sets the given states_to_set into the current_state |
---|
131 | * passed in. The result is returned to the user in current_state. |
---|
132 | * |
---|
133 | * @param[in] states_to_set is the state bits to set |
---|
134 | * @param[in] current_state is the state set to add them to |
---|
135 | * |
---|
136 | * @return This method returns the updated states value. |
---|
137 | */ |
---|
138 | RTEMS_INLINE_ROUTINE States_Control _States_Set ( |
---|
139 | States_Control states_to_set, |
---|
140 | States_Control current_state |
---|
141 | ) |
---|
142 | { |
---|
143 | return (current_state | states_to_set); |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * This function clears the given states_to_clear into the current_state |
---|
148 | * passed in. The result is returned to the user in current_state. |
---|
149 | * |
---|
150 | * @param[in] states_to_clear is the state bits to clean |
---|
151 | * @param[in] current_state is the state set to remove them from |
---|
152 | * |
---|
153 | * @return This method returns the updated states value. |
---|
154 | */ |
---|
155 | RTEMS_INLINE_ROUTINE States_Control _States_Clear ( |
---|
156 | States_Control states_to_clear, |
---|
157 | States_Control current_state |
---|
158 | ) |
---|
159 | { |
---|
160 | return (current_state & ~states_to_clear); |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * This function returns true if the_states indicates that the |
---|
165 | * state is READY, and false otherwise. |
---|
166 | * |
---|
167 | * @param[in] the_states is the task state set to test |
---|
168 | * |
---|
169 | * @return This method returns true if the desired state condition is set. |
---|
170 | */ |
---|
171 | RTEMS_INLINE_ROUTINE bool _States_Is_ready ( |
---|
172 | States_Control the_states |
---|
173 | ) |
---|
174 | { |
---|
175 | return (the_states == STATES_READY); |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * This function returns true if the DORMANT state is the ONLY state |
---|
180 | * set in the_states, and false otherwise. |
---|
181 | * |
---|
182 | * @param[in] the_states is the task state set to test |
---|
183 | * |
---|
184 | * @return This method returns true if the desired state condition is set. |
---|
185 | */ |
---|
186 | RTEMS_INLINE_ROUTINE bool _States_Is_only_dormant ( |
---|
187 | States_Control the_states |
---|
188 | ) |
---|
189 | { |
---|
190 | return (the_states == STATES_DORMANT); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * This function returns true if the DORMANT state is set in |
---|
195 | * the_states, and false otherwise. |
---|
196 | * |
---|
197 | * @param[in] the_states is the task state set to test |
---|
198 | * |
---|
199 | * @return This method returns true if the desired state condition is set. |
---|
200 | */ |
---|
201 | RTEMS_INLINE_ROUTINE bool _States_Is_dormant ( |
---|
202 | States_Control the_states |
---|
203 | ) |
---|
204 | { |
---|
205 | return (the_states & STATES_DORMANT); |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | * This function returns true if the SUSPENDED state is set in |
---|
210 | * the_states, and false otherwise. |
---|
211 | * |
---|
212 | * @param[in] the_states is the task state set to test |
---|
213 | * |
---|
214 | * @return This method returns true if the desired state condition is set. |
---|
215 | */ |
---|
216 | RTEMS_INLINE_ROUTINE bool _States_Is_suspended ( |
---|
217 | States_Control the_states |
---|
218 | ) |
---|
219 | { |
---|
220 | return (the_states & STATES_SUSPENDED); |
---|
221 | } |
---|
222 | |
---|
223 | /** |
---|
224 | * This function returns true if the DELAYING state is set in |
---|
225 | * the_states, and false otherwise. |
---|
226 | * |
---|
227 | * @param[in] the_states is the task state set to test |
---|
228 | * |
---|
229 | * @return This method returns true if the desired state condition is set. |
---|
230 | */ |
---|
231 | RTEMS_INLINE_ROUTINE bool _States_Is_delaying ( |
---|
232 | States_Control the_states |
---|
233 | ) |
---|
234 | { |
---|
235 | return (the_states & STATES_DELAYING); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * This function returns true if the WAITING_FOR_SEGMENT state is set in |
---|
240 | * the_states, and false otherwise. |
---|
241 | * |
---|
242 | * @param[in] the_states is the task state set to test |
---|
243 | * |
---|
244 | * @return This method returns true if the desired state condition is set. |
---|
245 | */ |
---|
246 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_segment ( |
---|
247 | States_Control the_states |
---|
248 | ) |
---|
249 | { |
---|
250 | return (the_states & STATES_WAITING_FOR_SEGMENT); |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * This function returns true if the WAITING_FOR_MESSAGE state is set in |
---|
255 | * the_states, and false otherwise. |
---|
256 | * |
---|
257 | * @param[in] the_states is the task state set to test |
---|
258 | * |
---|
259 | * @return This method returns true if the desired state condition is set. |
---|
260 | */ |
---|
261 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_message ( |
---|
262 | States_Control the_states |
---|
263 | ) |
---|
264 | { |
---|
265 | return (the_states & STATES_WAITING_FOR_MESSAGE); |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * This function returns true if the WAITING_FOR_EVENT state is set in |
---|
270 | * the_states, and false otherwise. |
---|
271 | * |
---|
272 | * @param[in] the_states is the task state set to test |
---|
273 | * |
---|
274 | * @return This method returns true if the desired state condition is set. |
---|
275 | */ |
---|
276 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_event ( |
---|
277 | States_Control the_states |
---|
278 | ) |
---|
279 | { |
---|
280 | return (the_states & STATES_WAITING_FOR_EVENT); |
---|
281 | } |
---|
282 | |
---|
283 | /** |
---|
284 | * This function returns true if the WAITING_FOR_SYSTEM_EVENT state is set in |
---|
285 | * the_states, and false otherwise. |
---|
286 | * |
---|
287 | * @param[in] the_states is the task state set to test |
---|
288 | * |
---|
289 | * @return This method returns true if the desired state condition is set. |
---|
290 | */ |
---|
291 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_system_event ( |
---|
292 | States_Control the_states |
---|
293 | ) |
---|
294 | { |
---|
295 | return (the_states & STATES_WAITING_FOR_SYSTEM_EVENT); |
---|
296 | } |
---|
297 | |
---|
298 | /** |
---|
299 | * This function returns true if the WAITING_FOR_MUTEX state |
---|
300 | * is set in the_states, and false otherwise. |
---|
301 | * |
---|
302 | * @param[in] the_states is the task state set to test |
---|
303 | * |
---|
304 | * @return This method returns true if the desired state condition is set. |
---|
305 | */ |
---|
306 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_mutex ( |
---|
307 | States_Control the_states |
---|
308 | ) |
---|
309 | { |
---|
310 | return (the_states & STATES_WAITING_FOR_MUTEX); |
---|
311 | } |
---|
312 | |
---|
313 | /** |
---|
314 | * This function returns true if the WAITING_FOR_SEMAPHORE state |
---|
315 | * is set in the_states, and false otherwise. |
---|
316 | * |
---|
317 | * @param[in] the_states is the task state set to test |
---|
318 | * |
---|
319 | * @return This method returns true if the desired state condition is set. |
---|
320 | */ |
---|
321 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_semaphore ( |
---|
322 | States_Control the_states |
---|
323 | ) |
---|
324 | { |
---|
325 | return (the_states & STATES_WAITING_FOR_SEMAPHORE); |
---|
326 | } |
---|
327 | |
---|
328 | /** |
---|
329 | * This function returns true if the WAITING_FOR_TIME state is set in |
---|
330 | * the_states, and false otherwise. |
---|
331 | * |
---|
332 | * @param[in] the_states is the task state set to test |
---|
333 | * |
---|
334 | * @return This method returns true if the desired state condition is set. |
---|
335 | */ |
---|
336 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_time ( |
---|
337 | States_Control the_states |
---|
338 | ) |
---|
339 | { |
---|
340 | return (the_states & STATES_WAITING_FOR_TIME); |
---|
341 | } |
---|
342 | |
---|
343 | /** |
---|
344 | * This function returns true if the WAITING_FOR_TIME state is set in |
---|
345 | * the_states, and false otherwise. |
---|
346 | * |
---|
347 | * @param[in] the_states is the task state set to test |
---|
348 | * |
---|
349 | * @return This method returns true if the desired state condition is set. |
---|
350 | */ |
---|
351 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_rpc_reply ( |
---|
352 | States_Control the_states |
---|
353 | ) |
---|
354 | { |
---|
355 | return (the_states & STATES_WAITING_FOR_RPC_REPLY); |
---|
356 | } |
---|
357 | |
---|
358 | /** |
---|
359 | * This function returns true if the WAITING_FOR_PERIOD state is set in |
---|
360 | * the_states, and false otherwise. |
---|
361 | * |
---|
362 | * @param[in] the_states is the task state set to test |
---|
363 | * |
---|
364 | * @return This method returns true if the desired state condition is set. |
---|
365 | */ |
---|
366 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_period ( |
---|
367 | States_Control the_states |
---|
368 | ) |
---|
369 | { |
---|
370 | return (the_states & STATES_WAITING_FOR_PERIOD); |
---|
371 | } |
---|
372 | |
---|
373 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_join_at_exit( |
---|
374 | States_Control the_states |
---|
375 | ) |
---|
376 | { |
---|
377 | return ( the_states & STATES_WAITING_FOR_JOIN_AT_EXIT ) != 0; |
---|
378 | } |
---|
379 | |
---|
380 | /** |
---|
381 | * This function returns true if the task's state is set in |
---|
382 | * way that allows it to be interrupted by a signal. |
---|
383 | * |
---|
384 | * @param[in] the_states is the task state set to test |
---|
385 | * |
---|
386 | * @return This method returns true if the desired state condition is set. |
---|
387 | */ |
---|
388 | RTEMS_INLINE_ROUTINE bool _States_Is_interruptible_by_signal ( |
---|
389 | States_Control the_states |
---|
390 | ) |
---|
391 | { |
---|
392 | return (the_states & STATES_INTERRUPTIBLE_BY_SIGNAL); |
---|
393 | |
---|
394 | } |
---|
395 | /** |
---|
396 | * This function returns true if one of the states which indicates |
---|
397 | * that a task is blocked waiting for a local resource is set in |
---|
398 | * the_states, and false otherwise. |
---|
399 | * |
---|
400 | * @param[in] the_states is the task state set to test |
---|
401 | * |
---|
402 | * @return This method returns true if the desired state condition is set. |
---|
403 | */ |
---|
404 | |
---|
405 | RTEMS_INLINE_ROUTINE bool _States_Is_locally_blocked ( |
---|
406 | States_Control the_states |
---|
407 | ) |
---|
408 | { |
---|
409 | return (the_states & STATES_LOCALLY_BLOCKED); |
---|
410 | } |
---|
411 | |
---|
412 | /** |
---|
413 | * This function returns true if one of the states which indicates |
---|
414 | * that a task is blocked is set in the_states, and false otherwise. |
---|
415 | * |
---|
416 | * @param[in] the_states is the task state set to test |
---|
417 | * |
---|
418 | * @return This method returns true if the state indicates that the |
---|
419 | * assocated thread is blocked. |
---|
420 | */ |
---|
421 | RTEMS_INLINE_ROUTINE bool _States_Is_blocked ( |
---|
422 | States_Control the_states |
---|
423 | ) |
---|
424 | { |
---|
425 | return (the_states & STATES_BLOCKED); |
---|
426 | } |
---|
427 | |
---|
428 | /** |
---|
429 | * This function returns true if any of the states in the mask |
---|
430 | * are set in the_states, and false otherwise. |
---|
431 | * |
---|
432 | * @param[in] the_states is the task state set to test |
---|
433 | * @param[in] mask is the state bits to test for |
---|
434 | * |
---|
435 | * @return This method returns true if the indicates state condition is set. |
---|
436 | */ |
---|
437 | RTEMS_INLINE_ROUTINE bool _States_Are_set ( |
---|
438 | States_Control the_states, |
---|
439 | States_Control mask |
---|
440 | ) |
---|
441 | { |
---|
442 | return ( (the_states & mask) != STATES_READY); |
---|
443 | } |
---|
444 | |
---|
445 | /** @} */ |
---|
446 | |
---|
447 | #ifdef __cplusplus |
---|
448 | } |
---|
449 | #endif |
---|
450 | |
---|
451 | #endif |
---|
452 | /* end of include file */ |
---|