mutex: support Zephyr RTOS mutex definition

Provide mutex implementation for Zephyr RTOS, so that libcoap inside Zephyr
can be used with COAP_CONSTRAINED_STACK enabled.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
Marcin Niestroj authored and Jon Shallow committed 2023-02-24 20:37:43 +00:00
1 parent bad2255ab4
commit 820bab3199
1 file changed
+11 -1
+11 -1
View File
@@ -70,7 +70,17 @@ typedef int coap_mutex_t;
#define coap_mutex_trylock(a) *(a) = 1
#define coap_mutex_unlock(a) *(a) = 0
#else /* !WITH_CONTIKI && !WITH_LWIP && !RIOT_VERSION && !HAVE_PTHREAD_H && !HAVE_PTHREAD_MUTEX_LOCK */
#elif defined(__ZEPHYR__)
#include <zephyr/sys/mutex.h>
typedef struct k_mutex coap_mutex_t;
#define COAP_MUTEX_DEFINE(_name) \
static SYS_MUTEX_DEFINE(_name)
#define coap_mutex_lock(a) sys_mutex_lock(a, K_FOREVER)
#define coap_mutex_trylock(a) sys_mutex_lock(a, K_NO_WAIT)
#define coap_mutex_unlock(a) sys_mutex_unlock(a)
#else /* !__ZEPYR__ && !WITH_CONTIKI && !WITH_LWIP && !RIOT_VERSION && !HAVE_PTHREAD_H && !HAVE_PTHREAD_MUTEX_LOCK */
/* define stub mutex functions */
#warning "stub mutex functions"
typedef int coap_mutex_t;