source: rtems/cpukit/include/rtems/thread.h @ 0fb724a

5
Last change on this file since 0fb724a was f14a04c6, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/17 at 05:38:07

Add RTEMS thread API

Update #2843.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef _RTEMS_THREAD_H
16#define _RTEMS_THREAD_H
17
18#include <sys/lock.h>
19#include <errno.h>
20#include <stdint.h>
21
22__BEGIN_DECLS
23
24/* Temporarily defined, will be shipped with a Newlib update */
25int _Semaphore_Wait_timed_ticks(struct _Semaphore_Control *, __uint32_t);
26
27/* Temporarily defined, will be shipped with a Newlib update */
28int _Semaphore_Try_wait(struct _Semaphore_Control *);
29
30/* Temporarily defined, will be shipped with a Newlib update */
31void _Semaphore_Post_binary(struct _Semaphore_Control *);
32
33typedef struct _Mutex_Control rtems_mutex;
34
35#define RTEMS_MUTEX_INITIALIZER( name ) _MUTEX_NAMED_INITIALIZER( name )
36
37static __inline void rtems_mutex_init( rtems_mutex *mutex, const char *name )
38{
39  _Mutex_Initialize_named( mutex, name );
40}
41
42static __inline const char *rtems_mutex_get_name( const rtems_mutex *mutex )
43{
44  return mutex->_Queue._name;
45}
46
47static __inline void rtems_mutex_set_name( rtems_mutex *mutex, const char *name )
48{
49  mutex->_Queue._name = name;
50}
51
52static __inline void rtems_mutex_lock( rtems_mutex *mutex )
53{
54  _Mutex_Acquire( mutex );
55}
56
57static __inline void rtems_mutex_unlock( rtems_mutex *mutex )
58{
59  _Mutex_Release( mutex );
60}
61
62static __inline void rtems_mutex_destroy( rtems_mutex *mutex )
63{
64  _Mutex_Destroy( mutex );
65}
66
67typedef struct _Mutex_recursive_Control rtems_recursive_mutex;
68
69#define RTEMS_RECURSIVE_MUTEX_INITIALIZER( name ) \
70  _MUTEX_RECURSIVE_NAMED_INITIALIZER( name )
71
72static __inline void rtems_recursive_mutex_init(
73  rtems_recursive_mutex *mutex, const char *name
74)
75{
76  _Mutex_recursive_Initialize_named( mutex, name );
77}
78
79static __inline const char *rtems_recursive_mutex_get_name(
80  const rtems_recursive_mutex *mutex
81)
82{
83  return mutex->_Mutex._Queue._name;
84}
85
86static __inline void rtems_recursive_mutex_set_name(
87  rtems_recursive_mutex *mutex, const char *name
88)
89{
90  mutex->_Mutex._Queue._name = name;
91}
92
93static __inline void rtems_recursive_mutex_lock(
94  rtems_recursive_mutex *mutex
95)
96{
97  _Mutex_recursive_Acquire( mutex );
98}
99
100static __inline void rtems_recursive_mutex_unlock(
101  rtems_recursive_mutex *mutex
102)
103{
104  _Mutex_recursive_Release( mutex );
105}
106
107static __inline void rtems_recursive_mutex_destroy(
108  rtems_recursive_mutex *mutex
109)
110{
111  _Mutex_recursive_Destroy( mutex );
112}
113
114typedef struct _Condition_Control rtems_condition_variable;
115
116#define RTEMS_CONDITION_VARIABLE_INITIALIZER( name ) \
117  _CONDITION_NAMED_INITIALIZER( name )
118
119static __inline void rtems_condition_variable_init(
120  rtems_condition_variable *condition_variable,
121  const char               *name
122)
123{
124  _Condition_Initialize_named( condition_variable, name );
125}
126
127static __inline const char *rtems_condition_variable_get_name(
128  const rtems_condition_variable *condition_variable
129)
130{
131  return condition_variable->_Queue._name;
132}
133
134static __inline void rtems_condition_variable_set_name(
135  rtems_condition_variable *condition_variable,
136  const char               *name
137)
138{
139  condition_variable->_Queue._name = name;
140}
141
142static __inline void rtems_condition_variable_wait(
143  rtems_condition_variable *condition_variable,
144  rtems_mutex *mutex
145)
146{
147  _Condition_Wait( condition_variable, mutex );
148}
149
150static __inline void rtems_condition_variable_signal(
151  rtems_condition_variable *condition_variable
152)
153{
154  _Condition_Broadcast( condition_variable );
155}
156
157static __inline void rtems_condition_variable_broadcast(
158  rtems_condition_variable *condition_variable
159)
160{
161  _Condition_Broadcast( condition_variable );
162}
163
164static __inline void rtems_condition_variable_destroy(
165  rtems_condition_variable *condition_variable
166)
167{
168  _Condition_Destroy( condition_variable );
169}
170
171typedef struct _Semaphore_Control rtems_counting_semaphore;
172
173#define RTEMS_COUNTING_SEMAPHORE_INITIALIZER( name, value ) \
174  _SEMAPHORE_NAMED_INITIALIZER( name, value )
175
176static __inline void rtems_counting_semaphore_init(
177  rtems_counting_semaphore *counting_semaphore,
178  const char               *name,
179  unsigned int              value
180)
181{
182  _Semaphore_Initialize_named( counting_semaphore, name, value );
183}
184
185static __inline const char *rtems_counting_semaphore_get_name(
186  const rtems_counting_semaphore *counting_semaphore
187)
188{
189  return counting_semaphore->_Queue._name;
190}
191
192static __inline void rtems_counting_semaphore_set_name(
193  rtems_counting_semaphore *counting_semaphore,
194  const char               *name
195)
196{
197  counting_semaphore->_Queue._name = name;
198}
199
200static __inline void rtems_counting_semaphore_wait(
201  rtems_counting_semaphore *counting_semaphore
202)
203{
204  _Semaphore_Wait( counting_semaphore );
205}
206
207static __inline void rtems_counting_semaphore_post(
208  rtems_counting_semaphore *counting_semaphore
209)
210{
211  _Semaphore_Post( counting_semaphore );
212}
213
214static __inline void rtems_counting_semaphore_destroy(
215  rtems_counting_semaphore *counting_semaphore
216)
217{
218  _Semaphore_Destroy( counting_semaphore );
219}
220
221typedef struct {
222  struct _Semaphore_Control Semaphore;
223} rtems_binary_semaphore;
224
225#define RTEMS_BINARY_SEMAPHORE_INITIALIZER( name ) \
226  { _SEMAPHORE_NAMED_INITIALIZER( name, 0 ) }
227
228static __inline void rtems_binary_semaphore_init(
229  rtems_binary_semaphore *binary_semaphore,
230  const char             *name
231)
232{
233  _Semaphore_Initialize_named( &binary_semaphore->Semaphore, name, 0 );
234}
235
236static __inline const char *rtems_binary_semaphore_get_name(
237  const rtems_binary_semaphore *binary_semaphore
238)
239{
240  return binary_semaphore->Semaphore._Queue._name;
241}
242
243static __inline void rtems_binary_semaphore_set_name(
244  rtems_binary_semaphore *binary_semaphore,
245  const char             *name
246)
247{
248  binary_semaphore->Semaphore._Queue._name = name;
249}
250
251static __inline void rtems_binary_semaphore_wait(
252  rtems_binary_semaphore *binary_semaphore
253)
254{
255  _Semaphore_Wait( &binary_semaphore->Semaphore );
256}
257
258static __inline int rtems_binary_semaphore_wait_timed_ticks(
259  rtems_binary_semaphore *binary_semaphore,
260  uint32_t                ticks
261)
262{
263  return _Semaphore_Wait_timed_ticks( &binary_semaphore->Semaphore, ticks );
264}
265
266static __inline int rtems_binary_semaphore_try_wait(
267  rtems_binary_semaphore *binary_semaphore
268)
269{
270  return _Semaphore_Try_wait( &binary_semaphore->Semaphore );
271}
272
273static __inline void rtems_binary_semaphore_post(
274  rtems_binary_semaphore *binary_semaphore
275)
276{
277  _Semaphore_Post_binary( &binary_semaphore->Semaphore );
278}
279
280static __inline void rtems_binary_semaphore_destroy(
281  rtems_binary_semaphore *binary_semaphore
282)
283{
284  _Semaphore_Destroy( &binary_semaphore->Semaphore );
285}
286
287__END_DECLS
288
289#endif /* _RTEMS_THREAD_H */
Note: See TracBrowser for help on using the repository browser.