Skip to content
Snippets Groups Projects
Commit 28b4ae1c authored by Andrew Tridgell's avatar Andrew Tridgell
Browse files

HAL_Linux: improved latency of timed semaphores

parent 6fa55d10
No related branches found
No related tags found
No related merge requests found
......@@ -18,11 +18,17 @@ bool LinuxSemaphore::take(uint32_t timeout_ms)
if (timeout_ms == 0) {
return pthread_mutex_lock(&_lock) == 0;
}
while (timeout_ms-- > 0) {
if (take_nonblocking()) return true;
hal.scheduler->delay(1);
if (take_nonblocking()) {
return true;
}
return take_nonblocking();
uint32_t start = hal.scheduler->micros();
do {
hal.scheduler->delay_microseconds(200);
if (take_nonblocking()) {
return true;
}
} while ((hal.scheduler->micros() - start) < timeout_ms*1000);
return false;
}
bool LinuxSemaphore::take_nonblocking()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment