source: rtems/cpukit/score/include/rtems/score/statesimpl.h @ 4e07d9b3

5
Last change on this file since 4e07d9b3 was 4e07d9b3, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 5, 2017 at 2:40:57 PM

score: Optimize thread state values

  • Property mode set to 100644
File size: 14.2 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.  More frequently used
37 *  states should use lower value bits to ease the use of immediate values on
38 *  RISC architectures.
39 */
40
41/** This macro corresponds to a task being ready. */
42#define STATES_READY                           0x00000000
43
44/**
45 * @brief This macro corresponds to a task which is blocked on a thread queue
46 * embedded in an object with an identifier.
47 *
48 * This thread state bit is intended to ease debugging and improve system
49 * diagnostics, see _Thread_Wait_get_id().
50 */
51#define STATES_THREAD_QUEUE_WITH_IDENTIFIER    0x00000001
52
53/** This macro corresponds to a task waiting for a mutex. */
54#define STATES_WAITING_FOR_MUTEX               0x00000002
55
56/** This macro corresponds to a task waiting for a semaphore. */
57#define STATES_WAITING_FOR_SEMAPHORE           0x00000004
58
59/** This macro corresponds to a task waiting for an event. */
60#define STATES_WAITING_FOR_EVENT               0x00000008
61
62/** This macro corresponds to a task waiting for a system event. */
63#define STATES_WAITING_FOR_SYSTEM_EVENT        0x00000010
64
65/** This macro corresponds to a task waiting for a message. */
66#define STATES_WAITING_FOR_MESSAGE             0x00000020
67
68/** This macro corresponds to a task waiting for a condition variable. */
69#define STATES_WAITING_FOR_CONDITION_VARIABLE  0x00000040
70
71/** This macro corresponds to a task waiting for a futex. */
72#define STATES_WAITING_FOR_FUTEX               0x00000080
73
74/** This macro corresponds to a task waiting for BSD wakeup. */
75#define STATES_WAITING_FOR_BSD_WAKEUP          0x00000100
76
77/** This macro corresponds to a task which is waiting for a timeout. */
78#define STATES_DELAYING                        0x00000200
79
80/** This macro corresponds to a task waiting for a period. */
81#define STATES_WAITING_FOR_PERIOD              0x00000400
82
83/** This macro corresponds to a task waiting for a signal. */
84#define STATES_WAITING_FOR_SIGNAL              0x00000800
85
86/** This macro corresponds to a task waiting for a barrier. */
87#define STATES_WAITING_FOR_BARRIER             0x00001000
88
89/** This macro corresponds to a task waiting for a RWLock. */
90#define STATES_WAITING_FOR_RWLOCK              0x00002000
91
92/** This macro corresponds to a task waiting for a join while exiting. */
93#define STATES_WAITING_FOR_JOIN_AT_EXIT        0x00004000
94
95/** This macro corresponds to a task waiting for a join. */
96#define STATES_WAITING_FOR_JOIN                0x00008000
97
98/** This macro corresponds to a task being suspended. */
99#define STATES_SUSPENDED                       0x00010000
100
101/** This macro corresponds to a task waiting for a fixed size segment. */
102#define STATES_WAITING_FOR_SEGMENT             0x00020000
103
104/** This macro corresponds to a task those life is changing. */
105#define STATES_LIFE_IS_CHANGING                0x00040000
106
107/** This macro corresponds to a task waiting until a specific TOD. */
108#define STATES_WAITING_FOR_TIME                0x00080000
109
110/** This macro corresponds to a task being held by the debugger. */
111#define STATES_DEBUGGER                        0x08000000
112
113/** This macro corresponds to a task which is in an interruptible
114 *  blocking state.
115 */
116#define STATES_INTERRUPTIBLE_BY_SIGNAL         0x10000000
117
118/** This macro corresponds to a task waiting for a reply to an MPCI request. */
119#define STATES_WAITING_FOR_RPC_REPLY           0x20000000
120
121/** This macro corresponds to a task being a zombie. */
122#define STATES_ZOMBIE                          0x40000000
123
124/** This macro corresponds to a task being created but not yet started. */
125#define STATES_DORMANT                         0x80000000
126
127/** This macro corresponds to a task waiting for a local object operation. */
128#define STATES_LOCALLY_BLOCKED ( STATES_THREAD_QUEUE_WITH_IDENTIFIER   | \
129                                 STATES_WAITING_FOR_SEGMENT            | \
130                                 STATES_WAITING_FOR_MESSAGE            | \
131                                 STATES_WAITING_FOR_SEMAPHORE          | \
132                                 STATES_WAITING_FOR_MUTEX              | \
133                                 STATES_WAITING_FOR_CONDITION_VARIABLE | \
134                                 STATES_WAITING_FOR_JOIN               | \
135                                 STATES_WAITING_FOR_SIGNAL             | \
136                                 STATES_WAITING_FOR_BARRIER            | \
137                                 STATES_WAITING_FOR_BSD_WAKEUP         | \
138                                 STATES_WAITING_FOR_FUTEX              | \
139                                 STATES_WAITING_FOR_RWLOCK             )
140
141/** This macro corresponds to a task waiting which is blocked. */
142#define STATES_BLOCKED         ( STATES_DELAYING                | \
143                                 STATES_LOCALLY_BLOCKED         | \
144                                 STATES_WAITING_FOR_TIME        | \
145                                 STATES_WAITING_FOR_PERIOD      | \
146                                 STATES_WAITING_FOR_EVENT       | \
147                                 STATES_WAITING_FOR_RPC_REPLY   | \
148                                 STATES_WAITING_FOR_SYSTEM_EVENT | \
149                                 STATES_INTERRUPTIBLE_BY_SIGNAL )
150
151/** All state bits set to one (provided for _Thread_Start()) */
152#define STATES_ALL_SET 0xffffffff
153
154/**
155 * This function sets the given states_to_set into the current_state
156 * passed in.  The result is returned to the user in current_state.
157 *
158 * @param[in] states_to_set is the state bits to set
159 * @param[in] current_state is the state set to add them to
160 *
161 * @return This method returns the updated states value.
162 */
163RTEMS_INLINE_ROUTINE States_Control _States_Set (
164  States_Control states_to_set,
165  States_Control current_state
166)
167{
168   return (current_state | states_to_set);
169}
170
171/**
172 * This function clears the given states_to_clear into the current_state
173 * passed in.  The result is returned to the user in current_state.
174 *
175 * @param[in] states_to_clear is the state bits to clean
176 * @param[in] current_state is the state set to remove them from
177 *
178 * @return This method returns the updated states value.
179 */
180RTEMS_INLINE_ROUTINE States_Control _States_Clear (
181  States_Control states_to_clear,
182  States_Control current_state
183)
184{
185   return (current_state & ~states_to_clear);
186}
187
188/**
189 * This function returns true if the_states indicates that the
190 * state is READY, 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_ready (
197  States_Control the_states
198)
199{
200   return (the_states == STATES_READY);
201}
202
203/**
204 * This function returns true if the DORMANT state is the ONLY state
205 * set in 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_only_dormant (
212  States_Control the_states
213)
214{
215   return (the_states == STATES_DORMANT);
216}
217
218/**
219 * This function returns true if the DORMANT 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_dormant (
227  States_Control the_states
228)
229{
230   return (the_states & STATES_DORMANT);
231}
232
233/**
234 * This function returns true if the SUSPENDED 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_suspended (
242  States_Control the_states
243)
244{
245   return (the_states & STATES_SUSPENDED);
246}
247
248/**
249 * This function returns true if the DELAYING 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_delaying (
257  States_Control the_states
258)
259{
260   return (the_states & STATES_DELAYING);
261}
262
263/**
264 * This function returns true if the WAITING_FOR_SEGMENT 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_segment (
272  States_Control the_states
273)
274{
275   return (the_states & STATES_WAITING_FOR_SEGMENT);
276}
277
278/**
279 * This function returns true if the WAITING_FOR_MESSAGE 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_message (
287  States_Control the_states
288)
289{
290   return (the_states & STATES_WAITING_FOR_MESSAGE);
291}
292
293/**
294 * This function returns true if the WAITING_FOR_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_event (
302  States_Control the_states
303)
304{
305   return (the_states & STATES_WAITING_FOR_EVENT);
306}
307
308/**
309 * This function returns true if the WAITING_FOR_SYSTEM_EVENT state is set in
310 * 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_system_event (
317  States_Control the_states
318)
319{
320   return (the_states & STATES_WAITING_FOR_SYSTEM_EVENT);
321}
322
323/**
324 * This function returns true if the WAITING_FOR_MUTEX 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_mutex (
332  States_Control the_states
333)
334{
335   return (the_states & STATES_WAITING_FOR_MUTEX);
336}
337
338/**
339 * This function returns true if the WAITING_FOR_SEMAPHORE state
340 * is set in 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_semaphore (
347  States_Control the_states
348)
349{
350   return (the_states & STATES_WAITING_FOR_SEMAPHORE);
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_time (
362  States_Control the_states
363)
364{
365   return (the_states & STATES_WAITING_FOR_TIME);
366}
367
368/**
369 * This function returns true if the WAITING_FOR_TIME 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_rpc_reply (
377  States_Control the_states
378)
379{
380   return (the_states & STATES_WAITING_FOR_RPC_REPLY);
381}
382
383/**
384 * This function returns true if the WAITING_FOR_PERIOD state is set in
385 * the_states, and false otherwise.
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_waiting_for_period (
392  States_Control the_states
393)
394{
395   return (the_states & STATES_WAITING_FOR_PERIOD);
396}
397
398RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_join_at_exit(
399  States_Control the_states
400)
401{
402   return ( the_states & STATES_WAITING_FOR_JOIN_AT_EXIT ) != 0;
403}
404
405/**
406 * This function returns true if the task's state is set in
407 * way that allows it to be interrupted by a signal.
408 *
409 * @param[in] the_states is the task state set to test
410 *
411 * @return This method returns true if the desired state condition is set.
412 */
413RTEMS_INLINE_ROUTINE bool _States_Is_interruptible_by_signal (
414  States_Control the_states
415)
416{
417   return (the_states & STATES_INTERRUPTIBLE_BY_SIGNAL);
418
419}
420/**
421 * This function returns true if one of the states which indicates
422 * that a task is blocked waiting for a local resource is set in
423 * the_states, and false otherwise.
424 *
425 * @param[in] the_states is the task state set to test
426 *
427 * @return This method returns true if the desired state condition is set.
428 */
429
430RTEMS_INLINE_ROUTINE bool _States_Is_locally_blocked (
431  States_Control the_states
432)
433{
434   return (the_states & STATES_LOCALLY_BLOCKED);
435}
436
437/**
438 * This function returns true if one of the states which indicates
439 * that a task is blocked is set in the_states, and false otherwise.
440 *
441 * @param[in] the_states is the task state set to test
442 *
443 * @return This method returns true if the state indicates that the
444 *         assocated thread is blocked.
445 */
446RTEMS_INLINE_ROUTINE bool _States_Is_blocked (
447  States_Control the_states
448)
449{
450   return (the_states & STATES_BLOCKED);
451}
452
453/**
454 * This function returns true if any of the states in the mask
455 * are set in the_states, and false otherwise.
456 *
457 * @param[in] the_states is the task state set to test
458 * @param[in] mask is the state bits to test for
459 *
460 * @return This method returns true if the indicates state condition is set.
461 */
462RTEMS_INLINE_ROUTINE bool _States_Are_set (
463  States_Control the_states,
464  States_Control mask
465)
466{
467   return ( (the_states & mask) != STATES_READY);
468}
469
470/** @} */
471
472#ifdef __cplusplus
473}
474#endif
475
476#endif
477/* end of include file */
Note: See TracBrowser for help on using the repository browser.