coroutine: add qemu_co_queue_restart_all()
It's common to wake up all waiting coroutines. Introduce the qemu_co_queue_restart_all() function to do this instead of looping over qemu_co_queue_next() in every caller. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
3951690a4a
commit
e8ee5e4c47
@ -516,7 +516,7 @@ static void run_dependent_requests(BDRVQcowState *s, QCowL2Meta *m)
|
|||||||
/* Restart all dependent requests */
|
/* Restart all dependent requests */
|
||||||
if (!qemu_co_queue_empty(&m->dependent_requests)) {
|
if (!qemu_co_queue_empty(&m->dependent_requests)) {
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
qemu_co_mutex_unlock(&s->lock);
|
||||||
while(qemu_co_queue_next(&m->dependent_requests));
|
qemu_co_queue_restart_all(&m->dependent_requests);
|
||||||
qemu_co_mutex_lock(&s->lock);
|
qemu_co_mutex_lock(&s->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,13 @@ bool qemu_co_queue_next(CoQueue *queue)
|
|||||||
return (next != NULL);
|
return (next != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qemu_co_queue_restart_all(CoQueue *queue)
|
||||||
|
{
|
||||||
|
while (qemu_co_queue_next(queue)) {
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool qemu_co_queue_empty(CoQueue *queue)
|
bool qemu_co_queue_empty(CoQueue *queue)
|
||||||
{
|
{
|
||||||
return (QTAILQ_FIRST(&queue->entries) == NULL);
|
return (QTAILQ_FIRST(&queue->entries) == NULL);
|
||||||
@ -144,13 +151,7 @@ void qemu_co_rwlock_unlock(CoRwlock *lock)
|
|||||||
assert(qemu_in_coroutine());
|
assert(qemu_in_coroutine());
|
||||||
if (lock->writer) {
|
if (lock->writer) {
|
||||||
lock->writer = false;
|
lock->writer = false;
|
||||||
while (!qemu_co_queue_empty(&lock->queue)) {
|
qemu_co_queue_restart_all(&lock->queue);
|
||||||
/*
|
|
||||||
* Wakeup every body. This will include some
|
|
||||||
* writers too.
|
|
||||||
*/
|
|
||||||
qemu_co_queue_next(&lock->queue);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
lock->reader--;
|
lock->reader--;
|
||||||
assert(lock->reader >= 0);
|
assert(lock->reader >= 0);
|
||||||
|
@ -130,6 +130,11 @@ void coroutine_fn qemu_co_queue_wait_insert_head(CoQueue *queue);
|
|||||||
*/
|
*/
|
||||||
bool qemu_co_queue_next(CoQueue *queue);
|
bool qemu_co_queue_next(CoQueue *queue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restarts all coroutines in the CoQueue and leaves the queue empty.
|
||||||
|
*/
|
||||||
|
void qemu_co_queue_restart_all(CoQueue *queue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the CoQueue is empty.
|
* Checks if the CoQueue is empty.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user