RTEMS 6.1-rc2
Loading...
Searching...
No Matches
condimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
10/*
11 * COPYRIGHT (c) 1989-2013.
12 * On-Line Applications Research Corporation (OAR).
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_POSIX_CONDIMPL_H
37#define _RTEMS_POSIX_CONDIMPL_H
38
39#include <errno.h>
40#include <pthread.h>
41
42#include <rtems/score/percpu.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49typedef struct {
50 unsigned long flags;
52 pthread_mutex_t *mutex;
54
55#define POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC 0x1UL
56
57#define POSIX_CONDITION_VARIABLES_FLAGS_MASK 0x1UL
58
59#define POSIX_CONDITION_VARIABLES_MAGIC 0x18dfb1feUL
60
65#define POSIX_CONDITION_VARIABLES_NO_MUTEX NULL
66
67#define POSIX_CONDITION_VARIABLES_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
68
69#define POSIX_CONDITION_VARIABLE_OF_THREAD_QUEUE_QUEUE( queue ) \
70 RTEMS_CONTAINER_OF( \
71 queue, POSIX_Condition_variables_Control, Queue.Queue )
72
76extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes;
77
78static inline POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get(
79 pthread_cond_t *cond
80)
81{
83}
84
85static inline void _POSIX_Condition_variables_Initialize(
87 const pthread_condattr_t *the_attr
88)
89{
90 unsigned long flags;
91
92 _Thread_queue_Queue_initialize( &the_cond->Queue.Queue, NULL );
93 the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
94
95 flags = (uintptr_t) the_cond ^ POSIX_CONDITION_VARIABLES_MAGIC;
96 flags &= ~POSIX_CONDITION_VARIABLES_FLAGS_MASK;
97
98 if ( the_attr->clock == CLOCK_MONOTONIC ) {
99 flags |= POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC;
100 }
101
102 the_cond->flags = flags;
103}
104
105static inline void _POSIX_Condition_variables_Destroy(
107)
108{
109 the_cond->flags = ~the_cond->flags;
110}
111
112static inline clockid_t _POSIX_Condition_variables_Get_clock(
113 unsigned long flags
114)
115{
116 if ( ( flags & POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC ) != 0 ) {
117 return CLOCK_MONOTONIC;
118 }
119
120 return CLOCK_REALTIME;
121}
122
123static inline Thread_Control *_POSIX_Condition_variables_Acquire(
125 Thread_queue_Context *queue_context
126)
127{
128 ISR_Level level;
129 Thread_Control *executing;
130
131 _Thread_queue_Context_ISR_disable( queue_context, level );
132 _Thread_queue_Context_set_ISR_level( queue_context, level );
133 executing = _Thread_Executing;
134 _Thread_queue_Queue_acquire_critical(
135 &the_cond->Queue.Queue,
136 &executing->Potpourri_stats,
137 &queue_context->Lock_context.Lock_context
138 );
139
140 return executing;
141}
142
143static inline void _POSIX_Condition_variables_Release(
145 Thread_queue_Context *queue_context
146)
147{
148 _Thread_queue_Queue_release(
149 &the_cond->Queue.Queue,
150 &queue_context->Lock_context.Lock_context
151 );
152}
153
161 pthread_cond_t *cond,
162 bool is_broadcast
163);
164
172 pthread_cond_t *cond,
173 pthread_mutex_t *mutex,
174 const struct timespec *abstime
175);
176
177bool _POSIX_Condition_variables_Auto_initialization(
179);
180
181#define POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ) \
182 do { \
183 if ( ( the_cond ) == NULL ) { \
184 return EINVAL; \
185 } \
186 flags = ( the_cond )->flags; \
187 if ( \
188 ( ( (uintptr_t) ( the_cond ) ^ POSIX_CONDITION_VARIABLES_MAGIC ) \
189 & ~POSIX_CONDITION_VARIABLES_FLAGS_MASK ) \
190 != ( flags & ~POSIX_CONDITION_VARIABLES_FLAGS_MASK ) \
191 ) { \
192 if ( !_POSIX_Condition_variables_Auto_initialization( the_cond ) ) { \
193 return EINVAL; \
194 } \
195 } \
196 } while ( 0 )
197
198#ifdef __cplusplus
199}
200#endif
201
202#endif
203/* end of include file */
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:113
#define POSIX_CONDITION_VARIABLES_NO_MUTEX
Definition: condimpl.h:65
const pthread_condattr_t _POSIX_Condition_variables_Default_attributes
Definition: conddefaultattributes.c:48
int _POSIX_Condition_variables_Signal_support(pthread_cond_t *cond, bool is_broadcast)
Implements wake up version of the "signal" operation.
Definition: condsignalsupp.c:50
uint32_t ISR_Level
Definition: isrlevel.h:60
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
POSIX Threads Private Support.
This header file provides the interfaces of the Per-CPU Information.
Definition: condimpl.h:49
Thread queue context for the thread queue methods.
Definition: threadq.h:216
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:221
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:148
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock....
Definition: threadqimpl.h:71
Definition: thread.h:812
Definition: mutex.h:4
This header file provides interfaces of the Thread Queue Handler which are only used by the implement...