RTEMS 6.1-rc5
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (c) 2017 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_THREAD_H
38#define _RTEMS_THREAD_H
39
40#include <sys/lock.h>
41#include <errno.h>
42#include <stdint.h>
43
44__BEGIN_DECLS
45
46/* Temporarily defined, will be shipped with a Newlib update */
47int _Semaphore_Wait_timed_ticks(struct _Semaphore_Control *, __uint32_t);
48
49/* Temporarily defined, will be shipped with a Newlib update */
50int _Semaphore_Try_wait(struct _Semaphore_Control *);
51
52/* Temporarily defined, will be shipped with a Newlib update */
53void _Semaphore_Post_binary(struct _Semaphore_Control *);
54
55typedef struct _Mutex_Control rtems_mutex;
56
67#define RTEMS_MUTEX_INITIALIZER( name ) _MUTEX_NAMED_INITIALIZER( name )
68
69static __inline void rtems_mutex_init( rtems_mutex *mutex, const char *name )
70{
71 _Mutex_Initialize_named( mutex, name );
72}
73
74static __inline const char *rtems_mutex_get_name( const rtems_mutex *mutex )
75{
76 return mutex->_Queue._name;
77}
78
79static __inline void rtems_mutex_set_name( rtems_mutex *mutex, const char *name )
80{
81 mutex->_Queue._name = name;
82}
83
84static __inline void rtems_mutex_lock( rtems_mutex *mutex )
85{
86 _Mutex_Acquire( mutex );
87}
88
89static __inline int rtems_mutex_try_lock( rtems_mutex *mutex )
90{
91 return _Mutex_Try_acquire( mutex );
92}
93
94static __inline void rtems_mutex_unlock( rtems_mutex *mutex )
95{
96 _Mutex_Release( mutex );
97}
98
99static __inline void rtems_mutex_destroy( rtems_mutex *mutex )
100{
101 _Mutex_Destroy( mutex );
102}
103
104typedef struct _Mutex_recursive_Control rtems_recursive_mutex;
105
106#define RTEMS_RECURSIVE_MUTEX_INITIALIZER( name ) \
107 _MUTEX_RECURSIVE_NAMED_INITIALIZER( name )
108
109static __inline void rtems_recursive_mutex_init(
110 rtems_recursive_mutex *mutex, const char *name
111)
112{
113 _Mutex_recursive_Initialize_named( mutex, name );
114}
115
116static __inline const char *rtems_recursive_mutex_get_name(
117 const rtems_recursive_mutex *mutex
118)
119{
120 return mutex->_Mutex._Queue._name;
121}
122
123static __inline void rtems_recursive_mutex_set_name(
124 rtems_recursive_mutex *mutex, const char *name
125)
126{
127 mutex->_Mutex._Queue._name = name;
128}
129
130static __inline void rtems_recursive_mutex_lock(
131 rtems_recursive_mutex *mutex
132)
133{
134 _Mutex_recursive_Acquire( mutex );
135}
136
137static __inline int rtems_recursive_mutex_try_lock(
138 rtems_recursive_mutex *mutex
139)
140{
141 return _Mutex_recursive_Try_acquire( mutex );
142}
143
144static __inline void rtems_recursive_mutex_unlock(
145 rtems_recursive_mutex *mutex
146)
147{
148 _Mutex_recursive_Release( mutex );
149}
150
151static __inline void rtems_recursive_mutex_destroy(
152 rtems_recursive_mutex *mutex
153)
154{
155 _Mutex_recursive_Destroy( mutex );
156}
157
158typedef struct _Condition_Control rtems_condition_variable;
159
160#define RTEMS_CONDITION_VARIABLE_INITIALIZER( name ) \
161 _CONDITION_NAMED_INITIALIZER( name )
162
163static __inline void rtems_condition_variable_init(
164 rtems_condition_variable *condition_variable,
165 const char *name
166)
167{
168 _Condition_Initialize_named( condition_variable, name );
169}
170
171static __inline const char *rtems_condition_variable_get_name(
172 const rtems_condition_variable *condition_variable
173)
174{
175 return condition_variable->_Queue._name;
176}
177
178static __inline void rtems_condition_variable_set_name(
179 rtems_condition_variable *condition_variable,
180 const char *name
181)
182{
183 condition_variable->_Queue._name = name;
184}
185
186static __inline void rtems_condition_variable_wait(
187 rtems_condition_variable *condition_variable,
188 rtems_mutex *mutex
189)
190{
191 _Condition_Wait( condition_variable, mutex );
192}
193
194static __inline void rtems_condition_variable_signal(
195 rtems_condition_variable *condition_variable
196)
197{
198 _Condition_Signal( condition_variable );
199}
200
201static __inline void rtems_condition_variable_broadcast(
202 rtems_condition_variable *condition_variable
203)
204{
205 _Condition_Broadcast( condition_variable );
206}
207
208static __inline void rtems_condition_variable_destroy(
209 rtems_condition_variable *condition_variable
210)
211{
212 _Condition_Destroy( condition_variable );
213}
214
215typedef struct _Semaphore_Control rtems_counting_semaphore;
216
217#define RTEMS_COUNTING_SEMAPHORE_INITIALIZER( name, value ) \
218 _SEMAPHORE_NAMED_INITIALIZER( name, value )
219
220static __inline void rtems_counting_semaphore_init(
221 rtems_counting_semaphore *counting_semaphore,
222 const char *name,
223 unsigned int value
224)
225{
226 _Semaphore_Initialize_named( counting_semaphore, name, value );
227}
228
229static __inline const char *rtems_counting_semaphore_get_name(
230 const rtems_counting_semaphore *counting_semaphore
231)
232{
233 return counting_semaphore->_Queue._name;
234}
235
236static __inline void rtems_counting_semaphore_set_name(
237 rtems_counting_semaphore *counting_semaphore,
238 const char *name
239)
240{
241 counting_semaphore->_Queue._name = name;
242}
243
244static __inline void rtems_counting_semaphore_wait(
245 rtems_counting_semaphore *counting_semaphore
246)
247{
248 _Semaphore_Wait( counting_semaphore );
249}
250
251static __inline int rtems_counting_semaphore_wait_timed_ticks(
252 rtems_counting_semaphore *counting_semaphore,
253 uint32_t ticks
254)
255{
256 return _Semaphore_Wait_timed_ticks( counting_semaphore, ticks );
257}
258
259static __inline int rtems_counting_semaphore_try_wait(
260 rtems_counting_semaphore *counting_semaphore
261)
262{
263 return _Semaphore_Try_wait( counting_semaphore );
264}
265
266static __inline void rtems_counting_semaphore_post(
267 rtems_counting_semaphore *counting_semaphore
268)
269{
270 _Semaphore_Post( counting_semaphore );
271}
272
273static __inline void rtems_counting_semaphore_destroy(
274 rtems_counting_semaphore *counting_semaphore
275)
276{
277 _Semaphore_Destroy( counting_semaphore );
278}
279
280typedef struct {
281 struct _Semaphore_Control Semaphore;
283
284#define RTEMS_BINARY_SEMAPHORE_INITIALIZER( name ) \
285 { _SEMAPHORE_NAMED_INITIALIZER( name, 0 ) }
286
287static __inline void rtems_binary_semaphore_init(
288 rtems_binary_semaphore *binary_semaphore,
289 const char *name
290)
291{
292 _Semaphore_Initialize_named( &binary_semaphore->Semaphore, name, 0 );
293}
294
295static __inline const char *rtems_binary_semaphore_get_name(
296 const rtems_binary_semaphore *binary_semaphore
297)
298{
299 return binary_semaphore->Semaphore._Queue._name;
300}
301
302static __inline void rtems_binary_semaphore_set_name(
303 rtems_binary_semaphore *binary_semaphore,
304 const char *name
305)
306{
307 binary_semaphore->Semaphore._Queue._name = name;
308}
309
310static __inline void rtems_binary_semaphore_wait(
311 rtems_binary_semaphore *binary_semaphore
312)
313{
314 _Semaphore_Wait( &binary_semaphore->Semaphore );
315}
316
317static __inline int rtems_binary_semaphore_wait_timed_ticks(
318 rtems_binary_semaphore *binary_semaphore,
319 uint32_t ticks
320)
321{
322 return _Semaphore_Wait_timed_ticks( &binary_semaphore->Semaphore, ticks );
323}
324
325static __inline int rtems_binary_semaphore_try_wait(
326 rtems_binary_semaphore *binary_semaphore
327)
328{
329 return _Semaphore_Try_wait( &binary_semaphore->Semaphore );
330}
331
332static __inline void rtems_binary_semaphore_post(
333 rtems_binary_semaphore *binary_semaphore
334)
335{
336 _Semaphore_Post_binary( &binary_semaphore->Semaphore );
337}
338
339static __inline void rtems_binary_semaphore_destroy(
340 rtems_binary_semaphore *binary_semaphore
341)
342{
343 _Semaphore_Destroy( &binary_semaphore->Semaphore );
344}
345
348__END_DECLS
349
350#endif /* _RTEMS_THREAD_H */
Definition: mutex.h:4
Definition: thread.h:280