source: rtems/cpukit/score/include/rtems/score/statesimpl.h @ 1461aba8

4.115
Last change on this file since 1461aba8 was 1461aba8, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/15 at 20:13:29

score: Use _Thread_Clear_state() for _Thread_Ready

  • Property mode set to 100644
File size: 14.5 KB
Line 
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
26extern "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/** All state bits set to one (provided for _Thread_Ready()) */
122#define STATES_ALL_SET 0xffffffff
123
124/**
125 * This function sets the given states_to_set into the current_state
126 * passed in.  The result is returned to the user in current_state.
127 *
128 * @param[in] states_to_set is the state bits to set
129 * @param[in] current_state is the state set to add them to
130 *
131 * @return This method returns the updated states value.
132 */
133RTEMS_INLINE_ROUTINE States_Control _States_Set (
134  States_Control states_to_set,
135  States_Control current_state
136)
137{
138   return (current_state | states_to_set);
139}
140
141/**
142 * This function clears the given states_to_clear into the current_state
143 * passed in.  The result is returned to the user in current_state.
144 *
145 * @param[in] states_to_clear is the state bits to clean
146 * @param[in] current_state is the state set to remove them from
147 *
148 * @return This method returns the updated states value.
149 */
150RTEMS_INLINE_ROUTINE States_Control _States_Clear (
151  States_Control states_to_clear,
152  States_Control current_state
153)
154{
155   return (current_state & ~states_to_clear);
156}
157
158/**
159 * This function returns true if the_states indicates that the
160 * state is READY, and false otherwise.
161 *
162 * @param[in] the_states is the task state set to test
163 *
164 * @return This method returns true if the desired state condition is set.
165 */
166RTEMS_INLINE_ROUTINE bool _States_Is_ready (
167  States_Control the_states
168)
169{
170   return (the_states == STATES_READY);
171}
172
173/**
174 * This function returns true if the DORMANT state is the ONLY state
175 * set in the_states, and false otherwise.
176 *
177 * @param[in] the_states is the task state set to test
178 *
179 * @return This method returns true if the desired state condition is set.
180 */
181RTEMS_INLINE_ROUTINE bool _States_Is_only_dormant (
182  States_Control the_states
183)
184{
185   return (the_states == STATES_DORMANT);
186}
187
188/**
189 * This function returns true if the DORMANT state is set in
190 * the_states, and false otherwise.
191 *
192 * @param[in] the_states is the task state set to test
193 *
194 * @return This method returns true if the desired state condition is set.
195 */
196RTEMS_INLINE_ROUTINE bool _States_Is_dormant (
197  States_Control the_states
198)
199{
200   return (the_states & STATES_DORMANT);
201}
202
203/**
204 * This function returns true if the SUSPENDED state is set in
205 * the_states, and false otherwise.
206 *
207 * @param[in] the_states is the task state set to test
208 *
209 * @return This method returns true if the desired state condition is set.
210 */
211RTEMS_INLINE_ROUTINE bool _States_Is_suspended (
212  States_Control the_states
213)
214{
215   return (the_states & STATES_SUSPENDED);
216}
217
218/**
219 * This function returns true if the DELAYING state is set in
220 * the_states, and false otherwise.
221 *
222 * @param[in] the_states is the task state set to test
223 *
224 * @return This method returns true if the desired state condition is set.
225 */
226RTEMS_INLINE_ROUTINE bool _States_Is_delaying (
227  States_Control the_states
228)
229{
230   return (the_states & STATES_DELAYING);
231}
232
233/**
234 * This function returns true if the WAITING_FOR_BUFFER state is set in
235 * the_states, and false otherwise.
236 *
237 * @param[in] the_states is the task state set to test
238 *
239 * @return This method returns true if the desired state condition is set.
240 */
241RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_buffer (
242  States_Control the_states
243)
244{
245   return (the_states & STATES_WAITING_FOR_BUFFER);
246}
247
248/**
249 * This function returns true if the WAITING_FOR_SEGMENT state is set in
250 * the_states, and false otherwise.
251 *
252 * @param[in] the_states is the task state set to test
253 *
254 * @return This method returns true if the desired state condition is set.
255 */
256RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_segment (
257  States_Control the_states
258)
259{
260   return (the_states & STATES_WAITING_FOR_SEGMENT);
261}
262
263/**
264 * This function returns true if the WAITING_FOR_MESSAGE state is set in
265 * the_states, and false otherwise.
266 *
267 * @param[in] the_states is the task state set to test
268 *
269 * @return This method returns true if the desired state condition is set.
270 */
271RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_message (
272  States_Control the_states
273)
274{
275   return (the_states & STATES_WAITING_FOR_MESSAGE);
276}
277
278/**
279 * This function returns true if the WAITING_FOR_EVENT state is set in
280 * the_states, and false otherwise.
281 *
282 * @param[in] the_states is the task state set to test
283 *
284 * @return This method returns true if the desired state condition is set.
285 */
286RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_event (
287  States_Control the_states
288)
289{
290   return (the_states & STATES_WAITING_FOR_EVENT);
291}
292
293/**
294 * This function returns true if the WAITING_FOR_SYSTEM_EVENT state is set in
295 * the_states, and false otherwise.
296 *
297 * @param[in] the_states is the task state set to test
298 *
299 * @return This method returns true if the desired state condition is set.
300 */
301RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_system_event (
302  States_Control the_states
303)
304{
305   return (the_states & STATES_WAITING_FOR_SYSTEM_EVENT);
306}
307
308/**
309 * This function returns true if the WAITING_FOR_MUTEX state
310 * is set in the_states, and false otherwise.
311 *
312 * @param[in] the_states is the task state set to test
313 *
314 * @return This method returns true if the desired state condition is set.
315 */
316RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_mutex (
317  States_Control the_states
318)
319{
320   return (the_states & STATES_WAITING_FOR_MUTEX);
321}
322
323/**
324 * This function returns true if the WAITING_FOR_SEMAPHORE state
325 * is set in the_states, and false otherwise.
326 *
327 * @param[in] the_states is the task state set to test
328 *
329 * @return This method returns true if the desired state condition is set.
330 */
331RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_semaphore (
332  States_Control the_states
333)
334{
335   return (the_states & STATES_WAITING_FOR_SEMAPHORE);
336}
337
338/**
339 * This function returns true if the WAITING_FOR_TIME state is set in
340 * the_states, and false otherwise.
341 *
342 * @param[in] the_states is the task state set to test
343 *
344 * @return This method returns true if the desired state condition is set.
345 */
346RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_time (
347  States_Control the_states
348)
349{
350   return (the_states & STATES_WAITING_FOR_TIME);
351}
352
353/**
354 * This function returns true if the WAITING_FOR_TIME state is set in
355 * the_states, and false otherwise.
356 *
357 * @param[in] the_states is the task state set to test
358 *
359 * @return This method returns true if the desired state condition is set.
360 */
361RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_rpc_reply (
362  States_Control the_states
363)
364{
365   return (the_states & STATES_WAITING_FOR_RPC_REPLY);
366}
367
368/**
369 * This function returns true if the WAITING_FOR_PERIOD state is set in
370 * the_states, and false otherwise.
371 *
372 * @param[in] the_states is the task state set to test
373 *
374 * @return This method returns true if the desired state condition is set.
375 */
376RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_period (
377  States_Control the_states
378)
379{
380   return (the_states & STATES_WAITING_FOR_PERIOD);
381}
382
383/**
384 * This function returns true if the task's state is set in
385 * way that allows it to be interrupted by a signal.
386 *
387 * @param[in] the_states is the task state set to test
388 *
389 * @return This method returns true if the desired state condition is set.
390 */
391RTEMS_INLINE_ROUTINE bool _States_Is_interruptible_by_signal (
392  States_Control the_states
393)
394{
395   return (the_states & STATES_INTERRUPTIBLE_BY_SIGNAL);
396
397}
398/**
399 * This function returns true if one of the states which indicates
400 * that a task is blocked waiting for a local resource is set in
401 * the_states, and false otherwise.
402 *
403 * @param[in] the_states is the task state set to test
404 *
405 * @return This method returns true if the desired state condition is set.
406 */
407
408RTEMS_INLINE_ROUTINE bool _States_Is_locally_blocked (
409  States_Control the_states
410)
411{
412   return (the_states & STATES_LOCALLY_BLOCKED);
413}
414
415/**
416 * This function returns true if one of the states which indicates
417 * that a task is blocked waiting for a local resource is set in
418 * the_states, and false otherwise.
419 *
420 * @param[in] the_states is the task state set to test
421 *
422 * @return This method returns true if the state indicates that the
423 *         assocated thread is waiting on a thread queue.
424 */
425RTEMS_INLINE_ROUTINE bool _States_Is_waiting_on_thread_queue (
426  States_Control the_states
427)
428{
429   return (the_states & STATES_WAITING_ON_THREAD_QUEUE);
430}
431
432/**
433 * This function returns true if one of the states which indicates
434 * that a task is blocked is set in the_states, and false otherwise.
435 *
436 * @param[in] the_states is the task state set to test
437 *
438 * @return This method returns true if the state indicates that the
439 *         assocated thread is blocked.
440 */
441RTEMS_INLINE_ROUTINE bool _States_Is_blocked (
442  States_Control the_states
443)
444{
445   return (the_states & STATES_BLOCKED);
446}
447
448/**
449 * This function returns true if any of the states in the mask
450 * are set in the_states, and false otherwise.
451 *
452 * @param[in] the_states is the task state set to test
453 * @param[in] mask is the state bits to test for
454 *
455 * @return This method returns true if the indicates state condition is set.
456 */
457RTEMS_INLINE_ROUTINE bool _States_Are_set (
458  States_Control the_states,
459  States_Control mask
460)
461{
462   return ( (the_states & mask) != STATES_READY);
463}
464
465/** @} */
466
467#ifdef __cplusplus
468}
469#endif
470
471#endif
472/* end of include file */
Note: See TracBrowser for help on using the repository browser.