Added timed wait semaphore

This commit is contained in:
Lorenz Meier
2015-11-23 19:50:44 +01:00
parent fb24a54ca4
commit e2894c4a46
+14
View File
@@ -75,6 +75,20 @@ int px4_sem_wait(px4_sem_t *s)
return 0;
}
int px4_sem_timedwait(px4_sem_t * s, const struct timespec * abstime)
{
pthread_mutex_lock(&(s->lock));
s->value--;
if (s->value < 0) {
pthread_cond_timedwait(&(s->wait), &(s->lock), abstime);
}
pthread_mutex_unlock(&(s->lock));
return 0;
}
int px4_sem_post(px4_sem_t *s)
{
pthread_mutex_lock(&(s->lock));