From 2bcb09560b285d65b9e7745d3bd76a6d66c41b86 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 22 Mar 2017 10:55:36 -0500 Subject: [PATCH] events: Fixed zero wait condition in non-rtos semaphore Before, if the semaphore recieved a wait of zero, the semaphore would erronously drop the ticker event to wake up the device, causing the device to go to sleep without any mechanism to wake itself up. During a dispatch operation, the event queue dispatches all events that have expired, so the call to equeue_sema_wait very rarely has a wait of zero. But this can happen when an event is posted just after a dispatch has occured. --- events/equeue/equeue_mbed.cpp | 4 +++- events/equeue/equeue_platform.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/events/equeue/equeue_mbed.cpp b/events/equeue/equeue_mbed.cpp index 5c72b38dea..0acb2cac34 100644 --- a/events/equeue/equeue_mbed.cpp +++ b/events/equeue/equeue_mbed.cpp @@ -131,7 +131,9 @@ static void equeue_sema_timeout(equeue_sema_t *s) { bool equeue_sema_wait(equeue_sema_t *s, int ms) { int signal = 0; Timeout timeout; - if (ms > 0) { + if (ms == 0) { + return false; + } else if (ms > 0) { timeout.attach_us(callback(equeue_sema_timeout, s), ms*1000); } diff --git a/events/equeue/equeue_platform.h b/events/equeue/equeue_platform.h index ef2a8e3863..8b7c4f735d 100644 --- a/events/equeue/equeue_platform.h +++ b/events/equeue/equeue_platform.h @@ -129,7 +129,8 @@ typedef volatile int equeue_sema_t; // The equeue_sema_wait waits for a semaphore to be signalled or returns // immediately if equeue_sema_signal had been called since the last // equeue_sema_wait. The equeue_sema_wait returns true if it detected that -// equeue_sema_signal had been called. +// equeue_sema_signal had been called. If ms is negative, equeue_sema_wait +// will wait for a signal indefinitely. int equeue_sema_create(equeue_sema_t *sema); void equeue_sema_destroy(equeue_sema_t *sema); void equeue_sema_signal(equeue_sema_t *sema);