distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
Semaphore.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_C_API_SEMAPHORE_H_
13 #define INCLUDE_DISTORTOS_C_API_SEMAPHORE_H_
14 
16 
17 #include <limits.h>
18 #include <stdint.h>
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif /* def __cplusplus */
24 
30 /*---------------------------------------------------------------------------------------------------------------------+
31 | global types
32 +---------------------------------------------------------------------------------------------------------------------*/
33 
43 {
46 
48  unsigned int value;
49 
51  unsigned int maxValue;
52 };
53 
54 /*---------------------------------------------------------------------------------------------------------------------+
55 | global defines
56 +---------------------------------------------------------------------------------------------------------------------*/
57 
69 #define DISTORTOS_SEMAPHORE_INITIALIZER(self, value, maxValue) \
70  {ESTD_INTRUSIVELIST_INITIALIZER((self).blockedList), (value) < (maxValue) ? (value) : (maxValue), (maxValue)}
71 
83 #define DISTORTOS_SEMAPHORE_CONSTRUCT_1(name, value, maxValue) \
84  struct distortos_Semaphore name = DISTORTOS_SEMAPHORE_INITIALIZER(name, value, maxValue)
85 
95 #define DISTORTOS_SEMAPHORE_CONSTRUCT(name, value) DISTORTOS_SEMAPHORE_CONSTRUCT_1(name, value, UINT_MAX)
96 
97 /*---------------------------------------------------------------------------------------------------------------------+
98 | global functions
99 +---------------------------------------------------------------------------------------------------------------------*/
100 
117 int distortos_Semaphore_construct_1(struct distortos_Semaphore* semaphore, unsigned int value, unsigned int maxValue);
118 
133 static inline int distortos_Semaphore_construct(struct distortos_Semaphore* const semaphore, const unsigned int value)
134 {
135  return distortos_Semaphore_construct_1(semaphore, value, UINT_MAX);
136 }
137 
152 
165 int distortos_Semaphore_getMaxValue(const struct distortos_Semaphore* semaphore, unsigned int* maxValue);
166 
181 int distortos_Semaphore_getValue(const struct distortos_Semaphore* semaphore, unsigned int* value);
182 
197 int distortos_Semaphore_post(struct distortos_Semaphore* semaphore);
198 
214 int distortos_Semaphore_tryWait(struct distortos_Semaphore* semaphore);
215 
235 int distortos_Semaphore_tryWaitFor(struct distortos_Semaphore* semaphore, int64_t duration);
236 
256 int distortos_Semaphore_tryWaitUntil(struct distortos_Semaphore* semaphore, int64_t timePoint);
257 
274 int distortos_Semaphore_wait(struct distortos_Semaphore* semaphore);
275 
280 #ifdef __cplusplus
281 } /* extern "C" */
282 #endif /* def __cplusplus */
283 
284 #endif /* INCLUDE_DISTORTOS_C_API_SEMAPHORE_H_ */
C-API for estd::IntrusiveList.
unsigned int maxValue
Definition: Semaphore.h:51
C-API equivalent of estd::IntrusiveList.
Definition: IntrusiveList.h:32
struct estd_IntrusiveList blockedList
Definition: Semaphore.h:45
int distortos_Semaphore_tryWait(struct distortos_Semaphore *semaphore)
C-API equivalent of distortos::Semaphore::tryWait()
Definition: C-API-Semaphore.cpp:79
int distortos_Semaphore_post(struct distortos_Semaphore *semaphore)
C-API equivalent of distortos::Semaphore::post()
Definition: C-API-Semaphore.cpp:70
unsigned int value
Definition: Semaphore.h:48
int distortos_Semaphore_destruct(struct distortos_Semaphore *semaphore)
C-API equivalent of distortos::Semaphore's destructor.
Definition: C-API-Semaphore.cpp:40
int distortos_Semaphore_tryWaitUntil(struct distortos_Semaphore *semaphore, int64_t timePoint)
C-API equivalent of distortos::Semaphore::tryWaitUntil()
Definition: C-API-Semaphore.cpp:97
int distortos_Semaphore_wait(struct distortos_Semaphore *semaphore)
C-API equivalent of distortos::Semaphore::wait()
Definition: C-API-Semaphore.cpp:106
int distortos_Semaphore_getValue(const struct distortos_Semaphore *semaphore, unsigned int *value)
C-API equivalent of distortos::Semaphore::getValue()
Definition: C-API-Semaphore.cpp:60
int distortos_Semaphore_getMaxValue(const struct distortos_Semaphore *semaphore, unsigned int *maxValue)
C-API equivalent of distortos::Semaphore::getMaxValue()
Definition: C-API-Semaphore.cpp:50
C-API equivalent of distortos::Semaphore.
Definition: Semaphore.h:42
int distortos_Semaphore_construct_1(struct distortos_Semaphore *semaphore, unsigned int value, unsigned int maxValue)
C-API equivalent of distortos::Semaphore's constructor.
Definition: C-API-Semaphore.cpp:30
int distortos_Semaphore_tryWaitFor(struct distortos_Semaphore *semaphore, int64_t duration)
C-API equivalent of distortos::Semaphore::tryWaitFor()
Definition: C-API-Semaphore.cpp:88
static int distortos_Semaphore_construct(struct distortos_Semaphore *const semaphore, const unsigned int value)
C-API equivalent of distortos::Semaphore's constructor, maxValue == UINT_MAX.
Definition: Semaphore.h:133