dpl_sem.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Inria
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef DPL_DPL_SEM_H
21 #define DPL_DPL_SEM_H
22 
23 #include <stdint.h>
24 
25 #include "dpl_types.h"
26 #include "dpl_error.h"
27 #include "os/os_sem.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 struct dpl_sem {
37  struct os_sem sem;
38 };
39 
50 static inline dpl_error_t dpl_sem_init(struct dpl_sem *sem, uint16_t tokens)
51 {
52  return (dpl_error_t) os_sem_init(&sem->sem, tokens);
53 }
54 
69 static inline dpl_error_t dpl_sem_pend(struct dpl_sem *sem, dpl_time_t timeout)
70 {
71  return (dpl_error_t) os_sem_pend(&sem->sem, timeout);
72 }
73 
83 static inline dpl_error_t dpl_sem_release(struct dpl_sem *sem)
84 {
85  return (dpl_error_t) os_sem_release(&sem->sem);
86 }
87 
91 static inline int16_t dpl_sem_get_count(struct dpl_sem *sem)
92 {
93  return os_sem_get_count(&sem->sem);
94 }
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif /* DPL_DPL_SEM_H */
uwb-core DPL (Decawave Porting Layer) error types
os_error_t dpl_error_t
dpl error type
Definition: dpl_error.h:51
static dpl_error_t dpl_sem_release(struct dpl_sem *sem)
Release a semaphore.
Definition: dpl_sem.h:83
static dpl_error_t dpl_sem_pend(struct dpl_sem *sem, dpl_time_t timeout)
Pend (wait) for a semaphore.
Definition: dpl_sem.h:69
static dpl_error_t dpl_sem_init(struct dpl_sem *sem, uint16_t tokens)
Initialize a semaphore.
Definition: dpl_sem.h:50
static int16_t dpl_sem_get_count(struct dpl_sem *sem)
Get current semaphore's count.
Definition: dpl_sem.h:91
uwb-core DPL (Decawave Porting Layer) types
os_time_t dpl_time_t
dpl time type
Definition: dpl_types.h:57
dpl semaphore wrapper
Definition: dpl_sem.h:36
struct os_sem sem
the semaphore
Definition: dpl_sem.h:37