Skip to content

Commit 2bcb095

Browse files
committed
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.
1 parent 75f6f2d commit 2bcb095

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

events/equeue/equeue_mbed.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ static void equeue_sema_timeout(equeue_sema_t *s) {
131131
bool equeue_sema_wait(equeue_sema_t *s, int ms) {
132132
int signal = 0;
133133
Timeout timeout;
134-
if (ms > 0) {
134+
if (ms == 0) {
135+
return false;
136+
} else if (ms > 0) {
135137
timeout.attach_us(callback(equeue_sema_timeout, s), ms*1000);
136138
}
137139

events/equeue/equeue_platform.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ typedef volatile int equeue_sema_t;
129129
// The equeue_sema_wait waits for a semaphore to be signalled or returns
130130
// immediately if equeue_sema_signal had been called since the last
131131
// equeue_sema_wait. The equeue_sema_wait returns true if it detected that
132-
// equeue_sema_signal had been called.
132+
// equeue_sema_signal had been called. If ms is negative, equeue_sema_wait
133+
// will wait for a signal indefinitely.
133134
int equeue_sema_create(equeue_sema_t *sema);
134135
void equeue_sema_destroy(equeue_sema_t *sema);
135136
void equeue_sema_signal(equeue_sema_t *sema);

0 commit comments

Comments
 (0)