mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-04 15:08:28 -04:00
29 lines
534 B
C++
29 lines
534 B
C++
|
|
#include "Semaphores.h"
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
using namespace Linux;
|
|
|
|
bool LinuxSemaphore::give()
|
|
{
|
|
return pthread_mutex_unlock(&_lock) == 0;
|
|
}
|
|
|
|
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);
|
|
}
|
|
return take_nonblocking();
|
|
}
|
|
|
|
bool LinuxSemaphore::take_nonblocking()
|
|
{
|
|
return pthread_mutex_trylock(&_lock) == 0;
|
|
}
|