distortos  v0.6.0
object-oriented C++ RTOS for microcontrollers
Mutex.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_C_API_MUTEX_H_
13 #define INCLUDE_DISTORTOS_C_API_MUTEX_H_
14 
16 
17 #include <stdint.h>
18 
19 #ifdef __cplusplus
20 extern "C"
21 {
22 #endif /* def __cplusplus */
23 
29 /*---------------------------------------------------------------------------------------------------------------------+
30 | global types
31 +---------------------------------------------------------------------------------------------------------------------*/
32 
44 {
47 
50 
52  void* owner;
53 
56 
58  uint8_t priorityCeiling;
59 
61  uint8_t typeProtocol;
62 };
63 
64 /*---------------------------------------------------------------------------------------------------------------------+
65 | global constants
66 +---------------------------------------------------------------------------------------------------------------------*/
67 
68 enum
69 {
76 };
77 
78 enum
79 {
86 };
87 
88 enum
89 {
92 };
93 
94 enum
95 {
98 };
99 
100 /*---------------------------------------------------------------------------------------------------------------------+
101 | global defines
102 +---------------------------------------------------------------------------------------------------------------------*/
103 
118 #define DISTORTOS_MUTEX_INITIALIZER(self, type, protocol, priorityCeiling) \
119  {ESTD_INTRUSIVELISTNODE_INITIALIZER((self).node), ESTD_INTRUSIVELIST_INITIALIZER((self).blockedList), \
120  NULL, 0, (priorityCeiling), \
121  (uint8_t)(((type) == distortos_Mutex_Type_normal || (type) == distortos_Mutex_Type_errorChecking || \
122  (type) == distortos_Mutex_Type_recursive ? \
123  (uint8_t)(type) : (uint8_t)distortos_Mutex_Type_normal) << distortos_Mutex_typeShift | \
124  ((protocol) == distortos_Mutex_Protocol_none || (protocol) == distortos_Mutex_Protocol_priorityInheritance || \
125  (protocol) == distortos_Mutex_Protocol_priorityProtect ? \
126  (uint8_t)(protocol) : (uint8_t)distortos_Mutex_Protocol_none) << distortos_Mutex_protocolShift)}
127 
142 #define DISTORTOS_MUTEX_CONSTRUCT_3(name, type, protocol, priorityCeiling) \
143  struct distortos_Mutex name = DISTORTOS_MUTEX_INITIALIZER(name, type, protocol, priorityCeiling)
144 
157 #define DISTORTOS_MUTEX_CONSTRUCT_2PC(name, protocol, priorityCeiling) \
158  DISTORTOS_MUTEX_CONSTRUCT_3(name, distortos_Mutex_Type_normal, protocol, priorityCeiling)
159 
172 #define DISTORTOS_MUTEX_CONSTRUCT_2TP(name, type, protocol) \
173  DISTORTOS_MUTEX_CONSTRUCT_3(name, type, protocol, 0)
174 
185 #define DISTORTOS_MUTEX_CONSTRUCT_1P(name, protocol) \
186  DISTORTOS_MUTEX_CONSTRUCT_3(name, distortos_Mutex_Type_normal, protocol, 0)
187 
199 #define DISTORTOS_MUTEX_CONSTRUCT_1T(name, type) \
200  DISTORTOS_MUTEX_CONSTRUCT_3(name, type, distortos_Mutex_Protocol_none, 0)
201 
211 #define DISTORTOS_MUTEX_CONSTRUCT(name) \
212  DISTORTOS_MUTEX_CONSTRUCT_3(name, distortos_Mutex_Type_normal, distortos_Mutex_Protocol_none, 0)
213 
214 /*---------------------------------------------------------------------------------------------------------------------+
215 | global functions
216 +---------------------------------------------------------------------------------------------------------------------*/
217 
238 int distortos_Mutex_construct_3(struct distortos_Mutex* mutex, uint8_t type, uint8_t protocol, uint8_t priorityCeiling);
239 
258 static inline int distortos_Mutex_construct_2pc(struct distortos_Mutex* const mutex, const uint8_t protocol,
259  const uint8_t priorityCeiling)
260 {
261  return distortos_Mutex_construct_3(mutex, distortos_Mutex_Type_normal, protocol, priorityCeiling);
262 }
263 
282 static inline int distortos_Mutex_construct_2tp(struct distortos_Mutex* const mutex, const uint8_t type,
283  const uint8_t protocol)
284 {
285  return distortos_Mutex_construct_3(mutex, type, protocol, 0);
286 }
287 
304 static inline int distortos_Mutex_construct_1p(struct distortos_Mutex* const mutex, const uint8_t protocol)
305 {
306  return distortos_Mutex_construct_3(mutex, distortos_Mutex_Type_normal, protocol, 0);
307 }
308 
326 static inline int distortos_Mutex_construct_1t(struct distortos_Mutex* const mutex, const uint8_t type)
327 {
329 }
330 
346 static inline int distortos_Mutex_construct(struct distortos_Mutex* const mutex)
347 {
349 }
350 
366 int distortos_Mutex_destruct(struct distortos_Mutex* mutex);
367 
390 int distortos_Mutex_lock(struct distortos_Mutex* mutex);
391 
414 int distortos_Mutex_tryLock(struct distortos_Mutex* mutex);
415 
441 int distortos_Mutex_tryLockFor(struct distortos_Mutex* mutex, int64_t duration);
442 
469 int distortos_Mutex_tryLockUntil(struct distortos_Mutex* mutex, int64_t timePoint);
470 
489 int distortos_Mutex_unlock(struct distortos_Mutex* mutex);
490 
495 #ifdef __cplusplus
496 } /* extern "C" */
497 #endif /* def __cplusplus */
498 
499 #endif /* INCLUDE_DISTORTOS_C_API_MUTEX_H_ */
static int distortos_Mutex_construct(struct distortos_Mutex *const mutex)
C-API equivalent of distortos::Mutex&#39;s constructor, type = distortos_Mutex_Type_normal, protocol = distortos_Mutex_Protocol_none, priorityCeiling = 0.
Definition: Mutex.h:346
C-API for estd::IntrusiveList.
Definition: Mutex.h:91
uint8_t priorityCeiling
Definition: Mutex.h:58
C-API equivalent of estd::IntrusiveList.
Definition: IntrusiveList.h:32
static int distortos_Mutex_construct_1t(struct distortos_Mutex *const mutex, const uint8_t type)
C-API equivalent of distortos::Mutex&#39;s constructor, protocol = distortos_Mutex_Protocol_none, priorityCeiling = 0.
Definition: Mutex.h:326
int distortos_Mutex_tryLock(struct distortos_Mutex *mutex)
C-API equivalent of distortos::Mutex::tryLock()
Definition: C-API-Mutex.cpp:91
int distortos_Mutex_tryLockUntil(struct distortos_Mutex *mutex, int64_t timePoint)
C-API equivalent of distortos::Mutex::tryLockUntil()
Definition: C-API-Mutex.cpp:109
C-API equivalent of estd::IntrusiveListNode.
Definition: IntrusiveListNode.h:30
Definition: Mutex.h:81
Definition: Mutex.h:85
static int distortos_Mutex_construct_1p(struct distortos_Mutex *const mutex, const uint8_t protocol)
C-API equivalent of distortos::Mutex&#39;s constructor, type = distortos_Mutex_Type_normal, priorityCeiling = 0.
Definition: Mutex.h:304
struct estd_IntrusiveListNode node
Definition: Mutex.h:46
int distortos_Mutex_lock(struct distortos_Mutex *mutex)
C-API equivalent of distortos::Mutex::lock()
Definition: C-API-Mutex.cpp:82
uint8_t typeProtocol
Definition: Mutex.h:61
int distortos_Mutex_tryLockFor(struct distortos_Mutex *mutex, int64_t duration)
C-API equivalent of distortos::Mutex::tryLockFor()
Definition: C-API-Mutex.cpp:100
static int distortos_Mutex_construct_2tp(struct distortos_Mutex *const mutex, const uint8_t type, const uint8_t protocol)
C-API equivalent of distortos::Mutex&#39;s constructor, priorityCeiling = 0.
Definition: Mutex.h:282
void * owner
Definition: Mutex.h:52
Definition: Mutex.h:97
int distortos_Mutex_construct_3(struct distortos_Mutex *mutex, uint8_t type, uint8_t protocol, uint8_t priorityCeiling)
C-API equivalent of distortos::Mutex&#39;s constructor.
Definition: C-API-Mutex.cpp:55
static int distortos_Mutex_construct_2pc(struct distortos_Mutex *const mutex, const uint8_t protocol, const uint8_t priorityCeiling)
C-API equivalent of distortos::Mutex&#39;s constructor, type = distortos_Mutex_Type_normal.
Definition: Mutex.h:258
struct estd_IntrusiveList blockedList
Definition: Mutex.h:49
Definition: Mutex.h:71
uint16_t recursiveLocksCount
Definition: Mutex.h:55
C-API equivalent of distortos::Mutex.
Definition: Mutex.h:43
int distortos_Mutex_destruct(struct distortos_Mutex *mutex)
C-API equivalent of distortos::Mutex&#39;s destructor.
Definition: C-API-Mutex.cpp:72
int distortos_Mutex_unlock(struct distortos_Mutex *mutex)
C-API equivalent of distortos::Mutex::unlock()
Definition: C-API-Mutex.cpp:118