RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
condimpl.h
Go to the documentation of this file.
1
8/*
9 * COPYRIGHT (c) 1989-2013.
10 * On-Line Applications Research Corporation (OAR).
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef _RTEMS_POSIX_CONDIMPL_H
18#define _RTEMS_POSIX_CONDIMPL_H
19
20#include <errno.h>
21#include <pthread.h>
22
23#include <rtems/score/percpu.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30typedef struct {
31 unsigned long flags;
33 pthread_mutex_t *mutex;
35
36#define POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC 0x1UL
37
38#define POSIX_CONDITION_VARIABLES_FLAGS_MASK 0x1UL
39
40#define POSIX_CONDITION_VARIABLES_MAGIC 0x18dfb1feUL
41
46#define POSIX_CONDITION_VARIABLES_NO_MUTEX NULL
47
48#define POSIX_CONDITION_VARIABLES_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
49
50#define POSIX_CONDITION_VARIABLE_OF_THREAD_QUEUE_QUEUE( queue ) \
51 RTEMS_CONTAINER_OF( \
52 queue, POSIX_Condition_variables_Control, Queue.Queue )
53
57extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes;
58
59static inline POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get(
60 pthread_cond_t *cond
61)
62{
64}
65
66RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Initialize(
68 const pthread_condattr_t *the_attr
69)
70{
71 unsigned long flags;
72
73 _Thread_queue_Queue_initialize( &the_cond->Queue.Queue, NULL );
74 the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
75
76 flags = (uintptr_t) the_cond ^ POSIX_CONDITION_VARIABLES_MAGIC;
77 flags &= ~POSIX_CONDITION_VARIABLES_FLAGS_MASK;
78
79 if ( the_attr->clock == CLOCK_MONOTONIC ) {
80 flags |= POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC;
81 }
82
83 the_cond->flags = flags;
84}
85
86RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Destroy(
88)
89{
90 the_cond->flags = ~the_cond->flags;
91}
92
93RTEMS_INLINE_ROUTINE clockid_t _POSIX_Condition_variables_Get_clock(
94 unsigned long flags
95)
96{
97 if ( ( flags & POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC ) != 0 ) {
98 return CLOCK_MONOTONIC;
99 }
100
101 return CLOCK_REALTIME;
102}
103
104RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Condition_variables_Acquire(
106 Thread_queue_Context *queue_context
107)
108{
109 ISR_Level level;
110 Thread_Control *executing;
111
112 _Thread_queue_Context_ISR_disable( queue_context, level );
113 _Thread_queue_Context_set_ISR_level( queue_context, level );
114 executing = _Thread_Executing;
115 _Thread_queue_Queue_acquire_critical(
116 &the_cond->Queue.Queue,
117 &executing->Potpourri_stats,
118 &queue_context->Lock_context.Lock_context
119 );
120
121 return executing;
122}
123
124RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Release(
126 Thread_queue_Context *queue_context
127)
128{
130 &the_cond->Queue.Queue,
131 &queue_context->Lock_context.Lock_context
132 );
133}
134
142 pthread_cond_t *cond,
143 bool is_broadcast
144);
145
153 pthread_cond_t *cond,
154 pthread_mutex_t *mutex,
155 const struct timespec *abstime
156);
157
158bool _POSIX_Condition_variables_Auto_initialization(
160);
161
162#define POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ) \
163 do { \
164 if ( ( the_cond ) == NULL ) { \
165 return EINVAL; \
166 } \
167 flags = ( the_cond )->flags; \
168 if ( \
169 ( ( (uintptr_t) ( the_cond ) ^ POSIX_CONDITION_VARIABLES_MAGIC ) \
170 & ~POSIX_CONDITION_VARIABLES_FLAGS_MASK ) \
171 != ( flags & ~POSIX_CONDITION_VARIABLES_FLAGS_MASK ) \
172 ) { \
173 if ( !_POSIX_Condition_variables_Auto_initialization( the_cond ) ) { \
174 return EINVAL; \
175 } \
176 } \
177 } while ( 0 )
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif
184/* end of include file */
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
int _POSIX_Condition_variables_Wait_support(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
POSIX condition variables wait support.
Definition: condwaitsupp.c:94
#define POSIX_CONDITION_VARIABLES_NO_MUTEX
Definition: condimpl.h:46
const pthread_condattr_t _POSIX_Condition_variables_Default_attributes
Definition: conddefaultattributes.c:29
int _POSIX_Condition_variables_Signal_support(pthread_cond_t *cond, bool is_broadcast)
Implements wake up version of the "signal" operation.
Definition: condsignalsupp.c:31
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
uint32_t ISR_Level
Definition: isrlevel.h:41
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_ISR_level(Thread_queue_Context *queue_context, ISR_Level level)
Sets the thread queue context ISR level.
Definition: threadqimpl.h:411
RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_release(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Releases the thread queue queue and enables interrupts.
Definition: threadqimpl.h:625
RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_initialize(Thread_queue_Queue *queue, const char *name)
Initializes the thread queue queue with the given name.
Definition: threadqimpl.h:547
POSIX Threads Private Support.
Definition: condimpl.h:30
Thread queue context for the thread queue methods.
Definition: threadq.h:198
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock....
Definition: threadqimpl.h:54
Definition: thread.h:732
Definition: mutex.h:4
Constants and Structures Associated with the Manipulation of Objects.