forked from ARMmbed/mbed-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events_sema.h
44 lines (35 loc) · 796 Bytes
/
events_sema.h
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
/*
* System specific semaphore implementation
*/
#ifndef EVENTS_SEMA_H
#define EVENTS_SEMA_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
// Semaphore type
//
// Optimal implementation is a binary semaphore,
// however a regular semaphore is sufficient.
#if defined(__unix__)
#include <pthread.h>
typedef struct {
pthread_mutex_t mutex;
pthread_cond_t cond;
} events_sema_t;
#elif defined(__MBED__)
#ifdef MBED_CONF_RTOS_PRESENT
typedef void *events_sema_t;
#else
typedef struct {} events_sema_t;
#endif
#endif
// Semaphore operations
int events_sema_create(events_sema_t *sema);
void events_sema_destroy(events_sema_t *sema);
void events_sema_release(events_sema_t *sema);
bool events_sema_wait(events_sema_t *sema, int ms);
#ifdef __cplusplus
}
#endif
#endif