Skip to content

Commit

Permalink
events: Fixed zero wait condition in non-rtos semaphore
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geky committed Aug 4, 2019
1 parent d682378 commit b2a4d7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion equeue_mbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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);
}

Expand Down
3 changes: 2 additions & 1 deletion equeue_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ typedef struct equeue_sema {
// 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);
Expand Down

0 comments on commit b2a4d7a

Please sign in to comment.