mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
queue_signalled: try to read once before sleeping
This commit is contained in:
parent
4bffe387a9
commit
f724a00033
1 changed files with 13 additions and 2 deletions
|
@ -95,24 +95,35 @@ int queue_signalled_push_many(struct queue_signalled *qs, void *ptr[], size_t cn
|
|||
|
||||
int queue_signalled_pull(struct queue_signalled *qs, void **ptr)
|
||||
{
|
||||
int ret;
|
||||
/* Make sure that qs->mutex is unlocked if this thread gets cancelled. */
|
||||
pthread_cleanup_push((void (*)(void*)) pthread_mutex_unlock, &qs->mutex);
|
||||
pthread_mutex_lock(&qs->mutex);
|
||||
pthread_cond_wait(&qs->ready, &qs->mutex);
|
||||
ret = queue_pull(&qs->queue, ptr);
|
||||
if (!ret)
|
||||
pthread_cond_wait(&qs->ready, &qs->mutex);
|
||||
pthread_mutex_unlock(&qs->mutex);
|
||||
pthread_cleanup_pop(0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return queue_pull(&qs->queue, ptr);
|
||||
}
|
||||
|
||||
int queue_signalled_pull_many(struct queue_signalled *qs, void *ptr[], size_t cnt)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Make sure that qs->mutex is unlocked if this thread gets cancelled. */
|
||||
pthread_cleanup_push((void (*)(void*)) pthread_mutex_unlock, &qs->mutex);
|
||||
pthread_mutex_lock(&qs->mutex);
|
||||
pthread_cond_wait(&qs->ready, &qs->mutex);
|
||||
ret = queue_pull_many(&qs->queue, ptr, cnt);
|
||||
if (!ret)
|
||||
pthread_cond_wait(&qs->ready, &qs->mutex);
|
||||
pthread_mutex_unlock(&qs->mutex);
|
||||
pthread_cleanup_pop(0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return queue_pull_many(&qs->queue, ptr, cnt);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue