source: rtems/cpukit/score/include/rtems/score/statesimpl.h @ 40188718

5
Last change on this file since 40188718 was 40188718, checked in by Sebastian Huber <sebastian.huber@…>, on 07/13/15 at 08:00:28

score: Add self-contained futex implementation

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