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 01/05/17 at 14:40:57

score: Optimize thread state values

  • Property mode set to 100644
File size: 14.2 KB
RevLine 
[1f0d013]1/**
2 * @file
3 *
4 * @brief Inlined Routines Associated with Thread State Information
[ac7d5ef0]5 *
[1f0d013]6 * This file contains the static inline implementation of the inlined
7 * routines associated with thread state information.
[baff4da]8 */
9
10/*
[b697bc6]11 *  COPYRIGHT (c) 1989-2012.
[ac7d5ef0]12 *  On-Line Applications Research Corporation (OAR).
13 *
[98e4ebf5]14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
[c499856]16 *  http://www.rtems.org/license/LICENSE.
[ac7d5ef0]17 */
18
[fe6c170c]19#ifndef _RTEMS_SCORE_STATESIMPL_H
20#define _RTEMS_SCORE_STATESIMPL_H
[ef49476]21
[fe6c170c]22#include <rtems/score/states.h>
23#include <rtems/score/basedefs.h>
[ac7d5ef0]24
[fe6c170c]25#ifdef __cplusplus
26extern "C" {
27#endif
[c5e2f7c]28
[baff4da]29/**
[1f0d013]30 * @addtogroup ScoreStates
[baff4da]31 */
[b697bc6]32/**@{**/
[baff4da]33
[fe6c170c]34/*
35 *  The following constants define the individual states which may be
[4e07d9b3]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.
[fe6c170c]39 */
40
41/** This macro corresponds to a task being ready. */
[2e6d9865]42#define STATES_READY                           0x00000000
[4e07d9b3]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
[fe6c170c]53/** This macro corresponds to a task waiting for a mutex. */
[4e07d9b3]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
[fe6c170c]68/** This macro corresponds to a task waiting for a condition variable. */
[4e07d9b3]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
[fe6c170c]80/** This macro corresponds to a task waiting for a period. */
[4e07d9b3]81#define STATES_WAITING_FOR_PERIOD              0x00000400
82
[fe6c170c]83/** This macro corresponds to a task waiting for a signal. */
[4e07d9b3]84#define STATES_WAITING_FOR_SIGNAL              0x00000800
85
[fe6c170c]86/** This macro corresponds to a task waiting for a barrier. */
[4e07d9b3]87#define STATES_WAITING_FOR_BARRIER             0x00001000
88
[fe6c170c]89/** This macro corresponds to a task waiting for a RWLock. */
[4e07d9b3]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
[f329353]95/** This macro corresponds to a task waiting for a join. */
[4e07d9b3]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
[fe6c170c]112
113/** This macro corresponds to a task which is in an interruptible
114 *  blocking state.
115 */
116#define STATES_INTERRUPTIBLE_BY_SIGNAL         0x10000000
[9a448aab]117
[4e07d9b3]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
[fe6c170c]126
127/** This macro corresponds to a task waiting for a local object operation. */
[9a448aab]128#define STATES_LOCALLY_BLOCKED ( STATES_THREAD_QUEUE_WITH_IDENTIFIER   | \
129                                 STATES_WAITING_FOR_SEGMENT            | \
[fe6c170c]130                                 STATES_WAITING_FOR_MESSAGE            | \
131                                 STATES_WAITING_FOR_SEMAPHORE          | \
132                                 STATES_WAITING_FOR_MUTEX              | \
133                                 STATES_WAITING_FOR_CONDITION_VARIABLE | \
[f329353]134                                 STATES_WAITING_FOR_JOIN               | \
[fe6c170c]135                                 STATES_WAITING_FOR_SIGNAL             | \
136                                 STATES_WAITING_FOR_BARRIER            | \
[b68cef17]137                                 STATES_WAITING_FOR_BSD_WAKEUP         | \
[9a448aab]138                                 STATES_WAITING_FOR_FUTEX              | \
[fe6c170c]139                                 STATES_WAITING_FOR_RWLOCK             )
140
141/** This macro corresponds to a task waiting which is blocked. */
142#define STATES_BLOCKED         ( STATES_DELAYING                | \
[56729d8]143                                 STATES_LOCALLY_BLOCKED         | \
[fe6c170c]144                                 STATES_WAITING_FOR_TIME        | \
145                                 STATES_WAITING_FOR_PERIOD      | \
146                                 STATES_WAITING_FOR_EVENT       | \
[56729d8]147                                 STATES_WAITING_FOR_RPC_REPLY   | \
[fe6c170c]148                                 STATES_WAITING_FOR_SYSTEM_EVENT | \
149                                 STATES_INTERRUPTIBLE_BY_SIGNAL )
150
[33829ce]151/** All state bits set to one (provided for _Thread_Start()) */
[1461aba8]152#define STATES_ALL_SET 0xffffffff
153
[baff4da]154/**
[1f0d013]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.
[cdea617]157 *
[1f0d013]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
[cdea617]160 *
[1f0d013]161 * @return This method returns the updated states value.
[ac7d5ef0]162 */
[503dc058]163RTEMS_INLINE_ROUTINE States_Control _States_Set (
[ac7d5ef0]164  States_Control states_to_set,
165  States_Control current_state
166)
167{
168   return (current_state | states_to_set);
169}
170
[baff4da]171/**
[1f0d013]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.
[cdea617]174 *
[e858f70]175 * @param[in] states_to_clear is the state bits to clean
[1f0d013]176 * @param[in] current_state is the state set to remove them from
[cdea617]177 *
[1f0d013]178 * @return This method returns the updated states value.
[ac7d5ef0]179 */
[503dc058]180RTEMS_INLINE_ROUTINE States_Control _States_Clear (
[ac7d5ef0]181  States_Control states_to_clear,
182  States_Control current_state
183)
184{
185   return (current_state & ~states_to_clear);
186}
187
[baff4da]188/**
[1f0d013]189 * This function returns true if the_states indicates that the
190 * state is READY, and false otherwise.
[cdea617]191 *
[1f0d013]192 * @param[in] the_states is the task state set to test
[cdea617]193 *
[1f0d013]194 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]195 */
[484a769]196RTEMS_INLINE_ROUTINE bool _States_Is_ready (
[ac7d5ef0]197  States_Control the_states
198)
199{
200   return (the_states == STATES_READY);
201}
202
[baff4da]203/**
[1f0d013]204 * This function returns true if the DORMANT state is the ONLY state
205 * set in the_states, and false otherwise.
[cdea617]206 *
[1f0d013]207 * @param[in] the_states is the task state set to test
[cdea617]208 *
[1f0d013]209 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]210 */
[484a769]211RTEMS_INLINE_ROUTINE bool _States_Is_only_dormant (
[ac7d5ef0]212  States_Control the_states
213)
214{
215   return (the_states == STATES_DORMANT);
216}
217
[baff4da]218/**
[1f0d013]219 * This function returns true if the DORMANT state is set in
220 * the_states, and false otherwise.
[cdea617]221 *
[1f0d013]222 * @param[in] the_states is the task state set to test
[cdea617]223 *
[1f0d013]224 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]225 */
[484a769]226RTEMS_INLINE_ROUTINE bool _States_Is_dormant (
[ac7d5ef0]227  States_Control the_states
228)
229{
230   return (the_states & STATES_DORMANT);
231}
232
[baff4da]233/**
[1f0d013]234 * This function returns true if the SUSPENDED state is set in
235 * the_states, and false otherwise.
[cdea617]236 *
[1f0d013]237 * @param[in] the_states is the task state set to test
[cdea617]238 *
[1f0d013]239 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]240 */
[484a769]241RTEMS_INLINE_ROUTINE bool _States_Is_suspended (
[ac7d5ef0]242  States_Control the_states
243)
244{
245   return (the_states & STATES_SUSPENDED);
246}
247
[baff4da]248/**
[1f0d013]249 * This function returns true if the DELAYING state is set in
250 * the_states, and false otherwise.
[cdea617]251 *
[1f0d013]252 * @param[in] the_states is the task state set to test
[cdea617]253 *
[1f0d013]254 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]255 */
[484a769]256RTEMS_INLINE_ROUTINE bool _States_Is_delaying (
[ac7d5ef0]257  States_Control the_states
258)
259{
260   return (the_states & STATES_DELAYING);
261}
262
[baff4da]263/**
[1f0d013]264 * This function returns true if the WAITING_FOR_SEGMENT state is set in
265 * the_states, and false otherwise.
[cdea617]266 *
[1f0d013]267 * @param[in] the_states is the task state set to test
[cdea617]268 *
[1f0d013]269 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]270 */
[484a769]271RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_segment (
[ac7d5ef0]272  States_Control the_states
273)
274{
275   return (the_states & STATES_WAITING_FOR_SEGMENT);
276}
277
[baff4da]278/**
[1f0d013]279 * This function returns true if the WAITING_FOR_MESSAGE state is set in
280 * the_states, and false otherwise.
[cdea617]281 *
[1f0d013]282 * @param[in] the_states is the task state set to test
[cdea617]283 *
[1f0d013]284 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]285 */
[484a769]286RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_message (
[ac7d5ef0]287  States_Control the_states
288)
289{
290   return (the_states & STATES_WAITING_FOR_MESSAGE);
291}
292
[baff4da]293/**
[1f0d013]294 * This function returns true if the WAITING_FOR_EVENT state is set in
295 * the_states, and false otherwise.
[cdea617]296 *
[1f0d013]297 * @param[in] the_states is the task state set to test
[cdea617]298 *
[1f0d013]299 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]300 */
[484a769]301RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_event (
[ac7d5ef0]302  States_Control the_states
303)
304{
305   return (the_states & STATES_WAITING_FOR_EVENT);
306}
307
[0edf263]308/**
[1f0d013]309 * This function returns true if the WAITING_FOR_SYSTEM_EVENT state is set in
310 * the_states, and false otherwise.
[0edf263]311 *
[1f0d013]312 * @param[in] the_states is the task state set to test
[0edf263]313 *
[1f0d013]314 * @return This method returns true if the desired state condition is set.
[0edf263]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
[baff4da]323/**
[1f0d013]324 * This function returns true if the WAITING_FOR_MUTEX state
325 * is set in the_states, and false otherwise.
[cdea617]326 *
[1f0d013]327 * @param[in] the_states is the task state set to test
[cdea617]328 *
[1f0d013]329 * @return This method returns true if the desired state condition is set.
[3a4ae6c]330 */
[484a769]331RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_mutex (
[3a4ae6c]332  States_Control the_states
333)
334{
335   return (the_states & STATES_WAITING_FOR_MUTEX);
336}
337
[baff4da]338/**
[1f0d013]339 * This function returns true if the WAITING_FOR_SEMAPHORE state
340 * is set in the_states, and false otherwise.
[cdea617]341 *
[1f0d013]342 * @param[in] the_states is the task state set to test
[cdea617]343 *
[1f0d013]344 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]345 */
[484a769]346RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_semaphore (
[ac7d5ef0]347  States_Control the_states
348)
349{
350   return (the_states & STATES_WAITING_FOR_SEMAPHORE);
351}
352
[baff4da]353/**
[1f0d013]354 * This function returns true if the WAITING_FOR_TIME state is set in
355 * the_states, and false otherwise.
[cdea617]356 *
[1f0d013]357 * @param[in] the_states is the task state set to test
[cdea617]358 *
[1f0d013]359 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]360 */
[484a769]361RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_time (
[ac7d5ef0]362  States_Control the_states
363)
364{
365   return (the_states & STATES_WAITING_FOR_TIME);
366}
367
[baff4da]368/**
[1f0d013]369 * This function returns true if the WAITING_FOR_TIME state is set in
370 * the_states, and false otherwise.
[cdea617]371 *
[1f0d013]372 * @param[in] the_states is the task state set to test
[cdea617]373 *
[1f0d013]374 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]375 */
[484a769]376RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_rpc_reply (
[ac7d5ef0]377  States_Control the_states
378)
379{
380   return (the_states & STATES_WAITING_FOR_RPC_REPLY);
381}
382
[baff4da]383/**
[1f0d013]384 * This function returns true if the WAITING_FOR_PERIOD state is set in
385 * the_states, and false otherwise.
[cdea617]386 *
[1f0d013]387 * @param[in] the_states is the task state set to test
[cdea617]388 *
[1f0d013]389 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]390 */
[484a769]391RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_period (
[ac7d5ef0]392  States_Control the_states
393)
394{
395   return (the_states & STATES_WAITING_FOR_PERIOD);
396}
397
[54550e04]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
[cdea617]405/**
[1f0d013]406 * This function returns true if the task's state is set in
407 * way that allows it to be interrupted by a signal.
[cdea617]408 *
[1f0d013]409 * @param[in] the_states is the task state set to test
[cdea617]410 *
[1f0d013]411 * @return This method returns true if the desired state condition is set.
[cdea617]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}
[baff4da]420/**
[1f0d013]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.
[cdea617]424 *
[1f0d013]425 * @param[in] the_states is the task state set to test
[cdea617]426 *
[1f0d013]427 * @return This method returns true if the desired state condition is set.
[ac7d5ef0]428 */
429
[484a769]430RTEMS_INLINE_ROUTINE bool _States_Is_locally_blocked (
[ac7d5ef0]431  States_Control the_states
432)
433{
434   return (the_states & STATES_LOCALLY_BLOCKED);
435}
436
[baff4da]437/**
[1f0d013]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.
[cdea617]440 *
[1f0d013]441 * @param[in] the_states is the task state set to test
[cdea617]442 *
[1f0d013]443 * @return This method returns true if the state indicates that the
444 *         assocated thread is blocked.
[ac7d5ef0]445 */
[484a769]446RTEMS_INLINE_ROUTINE bool _States_Is_blocked (
[ac7d5ef0]447  States_Control the_states
448)
449{
450   return (the_states & STATES_BLOCKED);
451}
452
[baff4da]453/**
[1f0d013]454 * This function returns true if any of the states in the mask
455 * are set in the_states, and false otherwise.
[cdea617]456 *
[1f0d013]457 * @param[in] the_states is the task state set to test
458 * @param[in] mask is the state bits to test for
[cdea617]459 *
[1f0d013]460 * @return This method returns true if the indicates state condition is set.
[ac7d5ef0]461 */
[484a769]462RTEMS_INLINE_ROUTINE bool _States_Are_set (
[ac7d5ef0]463  States_Control the_states,
464  States_Control mask
465)
466{
467   return ( (the_states & mask) != STATES_READY);
468}
469
[1f0d013]470/** @} */
[baff4da]471
[fe6c170c]472#ifdef __cplusplus
473}
474#endif
475
[ac7d5ef0]476#endif
477/* end of include file */
Note: See TracBrowser for help on using the repository browser.