From a02e57dd6d239657a21631203f327ad858ea5d74 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Sat, 7 Dec 2024 11:09:50 +0100 Subject: [PATCH] Improve semaphore implementation --- src/system/rpi_pico/system.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/system/rpi_pico/system.c b/src/system/rpi_pico/system.c index ee4b4b4fb..c0c4f1bf8 100644 --- a/src/system/rpi_pico/system.c +++ b/src/system/rpi_pico/system.c @@ -135,7 +135,7 @@ z_result_t _z_mutex_try_lock(_z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, z_result_t _z_mutex_unlock(_z_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } /*------------------ CondVar ------------------*/ -static UBaseType_t CONDVAR_MAX_WAITERS_COUNT = 255; +static UBaseType_t CONDVAR_MAX_WAITERS_COUNT = UINT_MAX; z_result_t _z_condvar_init(_z_condvar_t *cv) { if (!cv) { @@ -199,13 +199,11 @@ z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { cv->waiters++; xSemaphoreGive(cv->mutex); - xSemaphoreGive(*m); + _z_mutex_unlock(m); xSemaphoreTake(cv->sem, portMAX_DELAY); - xSemaphoreTake(*m, portMAX_DELAY); - - return _Z_RES_OK; + return _z_mutex_lock(m); } #endif // Z_MULTI_THREAD == 1