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.
pull/3991/head
Christopher Haster 2017-03-22 10:55:36 -05:00
parent 75f6f2db30
commit 2bcb09560b
2 changed files with 5 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);