summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/thread.h
blob: feee612d2297f2b856a49e7ff5f6efb8e1114e35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef _RTEMS_THREAD_H
#define _RTEMS_THREAD_H

#include <sys/lock.h>
#include <errno.h>
#include <stdint.h>

__BEGIN_DECLS

/* Temporarily defined, will be shipped with a Newlib update */
int _Semaphore_Wait_timed_ticks(struct _Semaphore_Control *, __uint32_t);

/* Temporarily defined, will be shipped with a Newlib update */
int _Semaphore_Try_wait(struct _Semaphore_Control *);

/* Temporarily defined, will be shipped with a Newlib update */
void _Semaphore_Post_binary(struct _Semaphore_Control *);

typedef struct _Mutex_Control rtems_mutex;

#define RTEMS_MUTEX_INITIALIZER( name ) _MUTEX_NAMED_INITIALIZER( name )

static __inline void rtems_mutex_init( rtems_mutex *mutex, const char *name )
{
  _Mutex_Initialize_named( mutex, name );
}

static __inline const char *rtems_mutex_get_name( const rtems_mutex *mutex )
{
  return mutex->_Queue._name;
}

static __inline void rtems_mutex_set_name( rtems_mutex *mutex, const char *name )
{
  mutex->_Queue._name = name;
}

static __inline void rtems_mutex_lock( rtems_mutex *mutex )
{
  _Mutex_Acquire( mutex );
}

static __inline void rtems_mutex_unlock( rtems_mutex *mutex )
{
  _Mutex_Release( mutex );
}

static __inline void rtems_mutex_destroy( rtems_mutex *mutex )
{
  _Mutex_Destroy( mutex );
}

typedef struct _Mutex_recursive_Control rtems_recursive_mutex;

#define RTEMS_RECURSIVE_MUTEX_INITIALIZER( name ) \
  _MUTEX_RECURSIVE_NAMED_INITIALIZER( name )

static __inline void rtems_recursive_mutex_init(
  rtems_recursive_mutex *mutex, const char *name
)
{
  _Mutex_recursive_Initialize_named( mutex, name );
}

static __inline const char *rtems_recursive_mutex_get_name(
  const rtems_recursive_mutex *mutex
)
{
  return mutex->_Mutex._Queue._name;
}

static __inline void rtems_recursive_mutex_set_name(
  rtems_recursive_mutex *mutex, const char *name
)
{
  mutex->_Mutex._Queue._name = name;
}

static __inline void rtems_recursive_mutex_lock(
  rtems_recursive_mutex *mutex
)
{
  _Mutex_recursive_Acquire( mutex );
}

static __inline void rtems_recursive_mutex_unlock(
  rtems_recursive_mutex *mutex
)
{
  _Mutex_recursive_Release( mutex );
}

static __inline void rtems_recursive_mutex_destroy(
  rtems_recursive_mutex *mutex
)
{
  _Mutex_recursive_Destroy( mutex );
}

typedef struct _Condition_Control rtems_condition_variable;

#define RTEMS_CONDITION_VARIABLE_INITIALIZER( name ) \
  _CONDITION_NAMED_INITIALIZER( name )

static __inline void rtems_condition_variable_init(
  rtems_condition_variable *condition_variable,
  const char               *name
)
{
  _Condition_Initialize_named( condition_variable, name );
}

static __inline const char *rtems_condition_variable_get_name(
  const rtems_condition_variable *condition_variable
)
{
  return condition_variable->_Queue._name;
}

static __inline void rtems_condition_variable_set_name(
  rtems_condition_variable *condition_variable,
  const char               *name
)
{
  condition_variable->_Queue._name = name;
}

static __inline void rtems_condition_variable_wait(
  rtems_condition_variable *condition_variable,
  rtems_mutex *mutex
)
{
  _Condition_Wait( condition_variable, mutex );
}

static __inline void rtems_condition_variable_signal(
  rtems_condition_variable *condition_variable
)
{
  _Condition_Broadcast( condition_variable );
}

static __inline void rtems_condition_variable_broadcast(
  rtems_condition_variable *condition_variable
)
{
  _Condition_Broadcast( condition_variable );
}

static __inline void rtems_condition_variable_destroy(
  rtems_condition_variable *condition_variable
)
{
  _Condition_Destroy( condition_variable );
}

typedef struct _Semaphore_Control rtems_counting_semaphore;

#define RTEMS_COUNTING_SEMAPHORE_INITIALIZER( name, value ) \
  _SEMAPHORE_NAMED_INITIALIZER( name, value )

static __inline void rtems_counting_semaphore_init(
  rtems_counting_semaphore *counting_semaphore,
  const char               *name,
  unsigned int              value
)
{
  _Semaphore_Initialize_named( counting_semaphore, name, value );
}

static __inline const char *rtems_counting_semaphore_get_name(
  const rtems_counting_semaphore *counting_semaphore
)
{
  return counting_semaphore->_Queue._name;
}

static __inline void rtems_counting_semaphore_set_name(
  rtems_counting_semaphore *counting_semaphore,
  const char               *name
)
{
  counting_semaphore->_Queue._name = name;
}

static __inline void rtems_counting_semaphore_wait(
  rtems_counting_semaphore *counting_semaphore
)
{
  _Semaphore_Wait( counting_semaphore );
}

static __inline void rtems_counting_semaphore_post(
  rtems_counting_semaphore *counting_semaphore
)
{
  _Semaphore_Post( counting_semaphore );
}

static __inline void rtems_counting_semaphore_destroy(
  rtems_counting_semaphore *counting_semaphore
)
{
  _Semaphore_Destroy( counting_semaphore );
}

typedef struct {
  struct _Semaphore_Control Semaphore;
} rtems_binary_semaphore;

#define RTEMS_BINARY_SEMAPHORE_INITIALIZER( name ) \
  { _SEMAPHORE_NAMED_INITIALIZER( name, 0 ) }

static __inline void rtems_binary_semaphore_init(
  rtems_binary_semaphore *binary_semaphore,
  const char             *name
)
{
  _Semaphore_Initialize_named( &binary_semaphore->Semaphore, name, 0 );
}

static __inline const char *rtems_binary_semaphore_get_name(
  const rtems_binary_semaphore *binary_semaphore
)
{
  return binary_semaphore->Semaphore._Queue._name;
}

static __inline void rtems_binary_semaphore_set_name(
  rtems_binary_semaphore *binary_semaphore,
  const char             *name
)
{
  binary_semaphore->Semaphore._Queue._name = name;
}

static __inline void rtems_binary_semaphore_wait(
  rtems_binary_semaphore *binary_semaphore
)
{
  _Semaphore_Wait( &binary_semaphore->Semaphore );
}

static __inline int rtems_binary_semaphore_wait_timed_ticks(
  rtems_binary_semaphore *binary_semaphore,
  uint32_t                ticks
)
{
  return _Semaphore_Wait_timed_ticks( &binary_semaphore->Semaphore, ticks );
}

static __inline int rtems_binary_semaphore_try_wait(
  rtems_binary_semaphore *binary_semaphore
)
{
  return _Semaphore_Try_wait( &binary_semaphore->Semaphore );
}

static __inline void rtems_binary_semaphore_post(
  rtems_binary_semaphore *binary_semaphore
)
{
  _Semaphore_Post_binary( &binary_semaphore->Semaphore );
}

static __inline void rtems_binary_semaphore_destroy(
  rtems_binary_semaphore *binary_semaphore
)
{
  _Semaphore_Destroy( &binary_semaphore->Semaphore );
}

__END_DECLS

#endif /* _RTEMS_THREAD_H */