The friendly Operating System for the Internet of Things
sema.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 TriaGnoSys GmbH
3  * 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
25 #ifndef SEMA_H
26 #define SEMA_H
27 
28 #include <stdint.h>
29 
30 #include "mutex.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
44 #define SEMA_CREATE(value) { (value), SEMA_OK, MUTEX_INIT }
45 
50 #define SEMA_CREATE_LOCKED() { (0), SEMA_OK, MUTEX_INIT_LOCKED }
51 
55 typedef enum {
56  SEMA_OK = 0,
57  SEMA_DESTROY,
58 } sema_state_t;
59 
63 typedef struct {
64  unsigned int value;
67 } sema_t;
68 
81 void sema_create(sema_t *sema, unsigned int value);
82 
98 void sema_destroy(sema_t *sema);
99 
112 int sema_wait_timed(sema_t *sema, uint64_t timeout);
113 
124 static inline int sema_wait(sema_t *sema)
125 {
126  return sema_wait_timed(sema, 0);
127 }
128 
140 int sema_try_wait(sema_t *sema);
141 
152 int sema_post(sema_t *sema);
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif /* SEMA_H */
159 
mutex_t mutex
mutex of the semaphore
Definition: sema.h:66
sema_state_t state
state of the semaphore
Definition: sema.h:65
unsigned int value
value of the semaphore
Definition: sema.h:64
static int sema_wait(sema_t *sema)
Wait for a semaphore being posted (without timeout).
Definition: sema.h:124
sema_state_t
A Semaphore states.
Definition: sema.h:55
void sema_destroy(sema_t *sema)
Destroys a semaphore.
A Semaphore.
Definition: sema.h:63
int sema_wait_timed(sema_t *sema, uint64_t timeout)
Wait for a semaphore being posted.
RIOT synchronization API.
int sema_post(sema_t *sema)
Signal semaphore.
void sema_create(sema_t *sema, unsigned int value)
Creates semaphore dynamically.
Mutex structure.
Definition: mutex.h:36
int sema_try_wait(sema_t *sema)
Test if the semaphore is posted.