mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-01 18:31:36 +08:00
semaphore: add px4_sem_trywait
directly mapped to the posix method sem_trywait
This commit is contained in:
@@ -91,6 +91,27 @@ int px4_sem_wait(px4_sem_t *s)
|
||||
return (ret) ? ret : mret;
|
||||
}
|
||||
|
||||
int px4_sem_trywait(px4_sem_t *s)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&(s->lock));
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (s->value <= 0) {
|
||||
errno = EAGAIN;
|
||||
ret = -1;
|
||||
|
||||
} else {
|
||||
s->value--;
|
||||
}
|
||||
|
||||
int mret = pthread_mutex_unlock(&(s->lock));
|
||||
|
||||
return (ret) ? ret : mret;
|
||||
}
|
||||
|
||||
int px4_sem_timedwait(px4_sem_t *s, const struct timespec *abstime)
|
||||
{
|
||||
int ret = pthread_mutex_lock(&(s->lock));
|
||||
|
||||
Reference in New Issue
Block a user