HAL_Linux: improved latency of timed semaphores

This commit is contained in:
Andrew Tridgell 2013-10-08 11:23:22 +11:00
parent 6fa55d101f
commit 28b4ae1c3a

View File

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