X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/blobdiff_plain/9ebcc693fb87247af18d94ba3c65229187f73a94..573021795371f41a23ed0fe0b5171f38bb96d86e:/rpp/include/rpp/mutex.h diff --git a/rpp/include/rpp/mutex.h b/rpp/include/rpp/mutex.h new file mode 100644 index 0000000..6c30c50 --- /dev/null +++ b/rpp/include/rpp/mutex.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 Czech Technical University in Prague + * + * Authors: + * - Michal Sojka + * + * This document contains proprietary information belonging to Czech + * Technical University in Prague. Passing on and copying of this + * document, and communication of its contents is not permitted + * without prior written authorization. + * + */ + +#ifndef RPP_MUTEX_H +#define RPP_MUTEX_H + +#ifndef RPP_THREADSAFE +#define RPP_THREADSAFE 1 +#endif + +#if RPP_THREADSAFE + +#include + +#define RPP_MUTEX_DEFINE(mutex) static xSemaphoreHandle mutex +#define RPP_MUTEX_INIT(mutex) (((mutex) = xSemaphoreCreateMutex()) != NULL) +#define RPP_MUTEX_LOCK(mutex) xSemaphoreTake((mutex), portMAX_DELAY) +#define RPP_MUTEX_UNLOCK(mutex) xSemaphoreGive(mutex) + +#else + +#define RPP_MUTEX_DEFINE(mutex) +#define RPP_MUTEX_INIT(mutex) true +#define RPP_MUTEX_LOCK(mutex) +#define RPP_MUTEX_UNLOCK(mutex) + +#endif + +#endif