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 0x00000 |
---|
41 | /** This macro corresponds to a task being created but not yet started. */ |
---|
42 | #define STATES_DORMANT 0x00001 |
---|
43 | /** This macro corresponds to a task being suspended. */ |
---|
44 | #define STATES_SUSPENDED 0x00002 |
---|
45 | /** This macro corresponds to a task which is waiting for a timeout. */ |
---|
46 | #define STATES_DELAYING 0x00008 |
---|
47 | /** This macro corresponds to a task waiting until a specific TOD. */ |
---|
48 | #define STATES_WAITING_FOR_TIME 0x00010 |
---|
49 | /** This macro corresponds to a task waiting for a variable length buffer. */ |
---|
50 | #define STATES_WAITING_FOR_BUFFER 0x00020 |
---|
51 | /** This macro corresponds to a task waiting for a fixed size segment. */ |
---|
52 | #define STATES_WAITING_FOR_SEGMENT 0x00040 |
---|
53 | /** This macro corresponds to a task waiting for a message. */ |
---|
54 | #define STATES_WAITING_FOR_MESSAGE 0x00080 |
---|
55 | /** This macro corresponds to a task waiting for an event. */ |
---|
56 | #define STATES_WAITING_FOR_EVENT 0x00100 |
---|
57 | /** This macro corresponds to a task waiting for a semaphore. */ |
---|
58 | #define STATES_WAITING_FOR_SEMAPHORE 0x00200 |
---|
59 | /** This macro corresponds to a task waiting for a mutex. */ |
---|
60 | #define STATES_WAITING_FOR_MUTEX 0x00400 |
---|
61 | /** This macro corresponds to a task waiting for a condition variable. */ |
---|
62 | #define STATES_WAITING_FOR_CONDITION_VARIABLE 0x00800 |
---|
63 | /** This macro corresponds to a task waiting for a join while exiting. */ |
---|
64 | #define STATES_WAITING_FOR_JOIN_AT_EXIT 0x01000 |
---|
65 | /** This macro corresponds to a task waiting for a reply to an MPCI request. */ |
---|
66 | #define STATES_WAITING_FOR_RPC_REPLY 0x02000 |
---|
67 | /** This macro corresponds to a task waiting for a period. */ |
---|
68 | #define STATES_WAITING_FOR_PERIOD 0x04000 |
---|
69 | /** This macro corresponds to a task waiting for a signal. */ |
---|
70 | #define STATES_WAITING_FOR_SIGNAL 0x08000 |
---|
71 | /** This macro corresponds to a task waiting for a barrier. */ |
---|
72 | #define STATES_WAITING_FOR_BARRIER 0x10000 |
---|
73 | /** This macro corresponds to a task waiting for a RWLock. */ |
---|
74 | #define STATES_WAITING_FOR_RWLOCK 0x20000 |
---|
75 | /** This macro corresponds to a task waiting for a system event. */ |
---|
76 | #define STATES_WAITING_FOR_SYSTEM_EVENT 0x40000 |
---|
77 | /** This macro corresponds to a task waiting for BSD wakeup. */ |
---|
78 | #define STATES_WAITING_FOR_BSD_WAKEUP 0x80000 |
---|
79 | /** This macro corresponds to a task waiting for a task termination. */ |
---|
80 | #define STATES_WAITING_FOR_TERMINATION 0x100000 |
---|
81 | /** This macro corresponds to a task being a zombie. */ |
---|
82 | #define STATES_ZOMBIE 0x200000 |
---|
83 | /** This macro corresponds to a task migrating to another scheduler. */ |
---|
84 | #define STATES_MIGRATING 0x400000 |
---|
85 | /** This macro corresponds to a task restarting. */ |
---|
86 | #define STATES_RESTARTING 0x800000 |
---|
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 | /** This macro corresponds to a task waiting for a local object operation. */ |
---|
94 | #define STATES_LOCALLY_BLOCKED ( STATES_WAITING_FOR_BUFFER | \ |
---|
95 | STATES_WAITING_FOR_SEGMENT | \ |
---|
96 | STATES_WAITING_FOR_MESSAGE | \ |
---|
97 | STATES_WAITING_FOR_SEMAPHORE | \ |
---|
98 | STATES_WAITING_FOR_MUTEX | \ |
---|
99 | STATES_WAITING_FOR_CONDITION_VARIABLE | \ |
---|
100 | STATES_WAITING_FOR_JOIN_AT_EXIT | \ |
---|
101 | STATES_WAITING_FOR_SIGNAL | \ |
---|
102 | STATES_WAITING_FOR_BARRIER | \ |
---|
103 | STATES_WAITING_FOR_BSD_WAKEUP | \ |
---|
104 | STATES_WAITING_FOR_RWLOCK ) |
---|
105 | |
---|
106 | /** This macro corresponds to a task waiting which is blocked on |
---|
107 | * a thread queue. */ |
---|
108 | #define STATES_WAITING_ON_THREAD_QUEUE \ |
---|
109 | ( STATES_LOCALLY_BLOCKED | \ |
---|
110 | STATES_WAITING_FOR_RPC_REPLY ) |
---|
111 | |
---|
112 | /** This macro corresponds to a task waiting which is blocked. */ |
---|
113 | #define STATES_BLOCKED ( STATES_DELAYING | \ |
---|
114 | STATES_WAITING_FOR_TIME | \ |
---|
115 | STATES_WAITING_FOR_PERIOD | \ |
---|
116 | STATES_WAITING_FOR_EVENT | \ |
---|
117 | STATES_WAITING_FOR_SYSTEM_EVENT | \ |
---|
118 | STATES_WAITING_ON_THREAD_QUEUE | \ |
---|
119 | STATES_INTERRUPTIBLE_BY_SIGNAL ) |
---|
120 | |
---|
121 | /** |
---|
122 | * This function sets the given states_to_set into the current_state |
---|
123 | * passed in. The result is returned to the user in current_state. |
---|
124 | * |
---|
125 | * @param[in] states_to_set is the state bits to set |
---|
126 | * @param[in] current_state is the state set to add them to |
---|
127 | * |
---|
128 | * @return This method returns the updated states value. |
---|
129 | */ |
---|
130 | RTEMS_INLINE_ROUTINE States_Control _States_Set ( |
---|
131 | States_Control states_to_set, |
---|
132 | States_Control current_state |
---|
133 | ) |
---|
134 | { |
---|
135 | return (current_state | states_to_set); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * This function clears the given states_to_clear into the current_state |
---|
140 | * passed in. The result is returned to the user in current_state. |
---|
141 | * |
---|
142 | * @param[in] states_to_clear is the state bits to clean |
---|
143 | * @param[in] current_state is the state set to remove them from |
---|
144 | * |
---|
145 | * @return This method returns the updated states value. |
---|
146 | */ |
---|
147 | RTEMS_INLINE_ROUTINE States_Control _States_Clear ( |
---|
148 | States_Control states_to_clear, |
---|
149 | States_Control current_state |
---|
150 | ) |
---|
151 | { |
---|
152 | return (current_state & ~states_to_clear); |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * This function returns true if the_states indicates that the |
---|
157 | * state is READY, and false otherwise. |
---|
158 | * |
---|
159 | * @param[in] the_states is the task state set to test |
---|
160 | * |
---|
161 | * @return This method returns true if the desired state condition is set. |
---|
162 | */ |
---|
163 | RTEMS_INLINE_ROUTINE bool _States_Is_ready ( |
---|
164 | States_Control the_states |
---|
165 | ) |
---|
166 | { |
---|
167 | return (the_states == STATES_READY); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * This function returns true if the DORMANT state is the ONLY state |
---|
172 | * set in the_states, and false otherwise. |
---|
173 | * |
---|
174 | * @param[in] the_states is the task state set to test |
---|
175 | * |
---|
176 | * @return This method returns true if the desired state condition is set. |
---|
177 | */ |
---|
178 | RTEMS_INLINE_ROUTINE bool _States_Is_only_dormant ( |
---|
179 | States_Control the_states |
---|
180 | ) |
---|
181 | { |
---|
182 | return (the_states == STATES_DORMANT); |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * This function returns true if the DORMANT state is set in |
---|
187 | * the_states, and false otherwise. |
---|
188 | * |
---|
189 | * @param[in] the_states is the task state set to test |
---|
190 | * |
---|
191 | * @return This method returns true if the desired state condition is set. |
---|
192 | */ |
---|
193 | RTEMS_INLINE_ROUTINE bool _States_Is_dormant ( |
---|
194 | States_Control the_states |
---|
195 | ) |
---|
196 | { |
---|
197 | return (the_states & STATES_DORMANT); |
---|
198 | } |
---|
199 | |
---|
200 | /** |
---|
201 | * This function returns true if the SUSPENDED state is set in |
---|
202 | * the_states, and false otherwise. |
---|
203 | * |
---|
204 | * @param[in] the_states is the task state set to test |
---|
205 | * |
---|
206 | * @return This method returns true if the desired state condition is set. |
---|
207 | */ |
---|
208 | RTEMS_INLINE_ROUTINE bool _States_Is_suspended ( |
---|
209 | States_Control the_states |
---|
210 | ) |
---|
211 | { |
---|
212 | return (the_states & STATES_SUSPENDED); |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * This function returns true if the DELAYING state is set in |
---|
217 | * the_states, and false otherwise. |
---|
218 | * |
---|
219 | * @param[in] the_states is the task state set to test |
---|
220 | * |
---|
221 | * @return This method returns true if the desired state condition is set. |
---|
222 | */ |
---|
223 | RTEMS_INLINE_ROUTINE bool _States_Is_delaying ( |
---|
224 | States_Control the_states |
---|
225 | ) |
---|
226 | { |
---|
227 | return (the_states & STATES_DELAYING); |
---|
228 | } |
---|
229 | |
---|
230 | /** |
---|
231 | * This function returns true if the WAITING_FOR_BUFFER state is set in |
---|
232 | * the_states, and false otherwise. |
---|
233 | * |
---|
234 | * @param[in] the_states is the task state set to test |
---|
235 | * |
---|
236 | * @return This method returns true if the desired state condition is set. |
---|
237 | */ |
---|
238 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_buffer ( |
---|
239 | States_Control the_states |
---|
240 | ) |
---|
241 | { |
---|
242 | return (the_states & STATES_WAITING_FOR_BUFFER); |
---|
243 | } |
---|
244 | |
---|
245 | /** |
---|
246 | * This function returns true if the WAITING_FOR_SEGMENT state is set in |
---|
247 | * the_states, and false otherwise. |
---|
248 | * |
---|
249 | * @param[in] the_states is the task state set to test |
---|
250 | * |
---|
251 | * @return This method returns true if the desired state condition is set. |
---|
252 | */ |
---|
253 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_segment ( |
---|
254 | States_Control the_states |
---|
255 | ) |
---|
256 | { |
---|
257 | return (the_states & STATES_WAITING_FOR_SEGMENT); |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | * This function returns true if the WAITING_FOR_MESSAGE state is set in |
---|
262 | * the_states, and false otherwise. |
---|
263 | * |
---|
264 | * @param[in] the_states is the task state set to test |
---|
265 | * |
---|
266 | * @return This method returns true if the desired state condition is set. |
---|
267 | */ |
---|
268 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_message ( |
---|
269 | States_Control the_states |
---|
270 | ) |
---|
271 | { |
---|
272 | return (the_states & STATES_WAITING_FOR_MESSAGE); |
---|
273 | } |
---|
274 | |
---|
275 | /** |
---|
276 | * This function returns true if the WAITING_FOR_EVENT state is set in |
---|
277 | * the_states, and false otherwise. |
---|
278 | * |
---|
279 | * @param[in] the_states is the task state set to test |
---|
280 | * |
---|
281 | * @return This method returns true if the desired state condition is set. |
---|
282 | */ |
---|
283 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_event ( |
---|
284 | States_Control the_states |
---|
285 | ) |
---|
286 | { |
---|
287 | return (the_states & STATES_WAITING_FOR_EVENT); |
---|
288 | } |
---|
289 | |
---|
290 | /** |
---|
291 | * This function returns true if the WAITING_FOR_SYSTEM_EVENT state is set in |
---|
292 | * the_states, and false otherwise. |
---|
293 | * |
---|
294 | * @param[in] the_states is the task state set to test |
---|
295 | * |
---|
296 | * @return This method returns true if the desired state condition is set. |
---|
297 | */ |
---|
298 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_system_event ( |
---|
299 | States_Control the_states |
---|
300 | ) |
---|
301 | { |
---|
302 | return (the_states & STATES_WAITING_FOR_SYSTEM_EVENT); |
---|
303 | } |
---|
304 | |
---|
305 | /** |
---|
306 | * This function returns true if the WAITING_FOR_MUTEX state |
---|
307 | * is set in the_states, and false otherwise. |
---|
308 | * |
---|
309 | * @param[in] the_states is the task state set to test |
---|
310 | * |
---|
311 | * @return This method returns true if the desired state condition is set. |
---|
312 | */ |
---|
313 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_mutex ( |
---|
314 | States_Control the_states |
---|
315 | ) |
---|
316 | { |
---|
317 | return (the_states & STATES_WAITING_FOR_MUTEX); |
---|
318 | } |
---|
319 | |
---|
320 | /** |
---|
321 | * This function returns true if the WAITING_FOR_SEMAPHORE state |
---|
322 | * is set in the_states, and false otherwise. |
---|
323 | * |
---|
324 | * @param[in] the_states is the task state set to test |
---|
325 | * |
---|
326 | * @return This method returns true if the desired state condition is set. |
---|
327 | */ |
---|
328 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_semaphore ( |
---|
329 | States_Control the_states |
---|
330 | ) |
---|
331 | { |
---|
332 | return (the_states & STATES_WAITING_FOR_SEMAPHORE); |
---|
333 | } |
---|
334 | |
---|
335 | /** |
---|
336 | * This function returns true if the WAITING_FOR_TIME state is set in |
---|
337 | * the_states, and false otherwise. |
---|
338 | * |
---|
339 | * @param[in] the_states is the task state set to test |
---|
340 | * |
---|
341 | * @return This method returns true if the desired state condition is set. |
---|
342 | */ |
---|
343 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_time ( |
---|
344 | States_Control the_states |
---|
345 | ) |
---|
346 | { |
---|
347 | return (the_states & STATES_WAITING_FOR_TIME); |
---|
348 | } |
---|
349 | |
---|
350 | /** |
---|
351 | * This function returns true if the WAITING_FOR_TIME state is set in |
---|
352 | * the_states, and false otherwise. |
---|
353 | * |
---|
354 | * @param[in] the_states is the task state set to test |
---|
355 | * |
---|
356 | * @return This method returns true if the desired state condition is set. |
---|
357 | */ |
---|
358 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_rpc_reply ( |
---|
359 | States_Control the_states |
---|
360 | ) |
---|
361 | { |
---|
362 | return (the_states & STATES_WAITING_FOR_RPC_REPLY); |
---|
363 | } |
---|
364 | |
---|
365 | /** |
---|
366 | * This function returns true if the WAITING_FOR_PERIOD state is set in |
---|
367 | * the_states, and false otherwise. |
---|
368 | * |
---|
369 | * @param[in] the_states is the task state set to test |
---|
370 | * |
---|
371 | * @return This method returns true if the desired state condition is set. |
---|
372 | */ |
---|
373 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_period ( |
---|
374 | States_Control the_states |
---|
375 | ) |
---|
376 | { |
---|
377 | return (the_states & STATES_WAITING_FOR_PERIOD); |
---|
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 waiting for a local resource is set in |
---|
415 | * the_states, and false otherwise. |
---|
416 | * |
---|
417 | * @param[in] the_states is the task state set to test |
---|
418 | * |
---|
419 | * @return This method returns true if the state indicates that the |
---|
420 | * assocated thread is waiting on a thread queue. |
---|
421 | */ |
---|
422 | RTEMS_INLINE_ROUTINE bool _States_Is_waiting_on_thread_queue ( |
---|
423 | States_Control the_states |
---|
424 | ) |
---|
425 | { |
---|
426 | return (the_states & STATES_WAITING_ON_THREAD_QUEUE); |
---|
427 | } |
---|
428 | |
---|
429 | /** |
---|
430 | * This function returns true if one of the states which indicates |
---|
431 | * that a task is blocked is set in the_states, and false otherwise. |
---|
432 | * |
---|
433 | * @param[in] the_states is the task state set to test |
---|
434 | * |
---|
435 | * @return This method returns true if the state indicates that the |
---|
436 | * assocated thread is blocked. |
---|
437 | */ |
---|
438 | RTEMS_INLINE_ROUTINE bool _States_Is_blocked ( |
---|
439 | States_Control the_states |
---|
440 | ) |
---|
441 | { |
---|
442 | return (the_states & STATES_BLOCKED); |
---|
443 | } |
---|
444 | |
---|
445 | /** |
---|
446 | * This function returns true if any of the states in the mask |
---|
447 | * are set in the_states, and false otherwise. |
---|
448 | * |
---|
449 | * @param[in] the_states is the task state set to test |
---|
450 | * @param[in] mask is the state bits to test for |
---|
451 | * |
---|
452 | * @return This method returns true if the indicates state condition is set. |
---|
453 | */ |
---|
454 | RTEMS_INLINE_ROUTINE bool _States_Are_set ( |
---|
455 | States_Control the_states, |
---|
456 | States_Control mask |
---|
457 | ) |
---|
458 | { |
---|
459 | return ( (the_states & mask) != STATES_READY); |
---|
460 | } |
---|
461 | |
---|
462 | /** @} */ |
---|
463 | |
---|
464 | #ifdef __cplusplus |
---|
465 | } |
---|
466 | #endif |
---|
467 | |
---|
468 | #endif |
---|
469 | /* end of include file */ |
---|