From 820bab31992f53965c8760f93ebd367fb995c2f7 Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Thu, 12 Jan 2023 15:28:10 +0100 Subject: [PATCH] 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 --- include/coap3/coap_mutex_internal.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/coap3/coap_mutex_internal.h b/include/coap3/coap_mutex_internal.h index 7a42bbde..aeb127ac 100644 --- a/include/coap3/coap_mutex_internal.h +++ b/include/coap3/coap_mutex_internal.h @@ -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 + +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;