Skip to content

Commit

Permalink
Improve semaphore implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 7, 2024
1 parent 5ac4d38 commit a02e57d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/system/rpi_pico/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a02e57d

Please sign in to comment.