]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/rpp/mutex.h
Make the RPP layer thread safe
[pes-rpp/rpp-lib.git] / rpp / include / rpp / mutex.h
1 /*
2  * Copyright (C) 2015 Czech Technical University in Prague
3  *
4  * Authors:
5  *     - Michal Sojka <sojkam1@fel.cvut.cz>
6  *
7  * This document contains proprietary information belonging to Czech
8  * Technical University in Prague. Passing on and copying of this
9  * document, and communication of its contents is not permitted
10  * without prior written authorization.
11  *
12  */
13
14 #ifndef RPP_MUTEX_H
15 #define RPP_MUTEX_H
16
17 #ifndef RPP_THREADSAFE
18 #define RPP_THREADSAFE 1
19 #endif
20
21 #if RPP_THREADSAFE
22
23 #include <os/semphr.h>
24
25 #define RPP_MUTEX_DEFINE(mutex) static xSemaphoreHandle mutex
26 #define RPP_MUTEX_INIT(mutex)   (((mutex) = xSemaphoreCreateMutex()) != NULL)
27 #define RPP_MUTEX_LOCK(mutex)   xSemaphoreTake((mutex), portMAX_DELAY)
28 #define RPP_MUTEX_UNLOCK(mutex) xSemaphoreGive(mutex)
29
30 #else
31
32 #define RPP_MUTEX_DEFINE(mutex)
33 #define RPP_MUTEX_INIT(mutex) true
34 #define RPP_MUTEX_LOCK(mutex)
35 #define RPP_MUTEX_UNLOCK(mutex)
36
37 #endif
38
39 #endif