You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
534 B
28 lines
534 B
|
|
#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; |
|
}
|
|
|