mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
coroutine-lock: qemu_co_queue_restart_all is a coroutine-only qemu_co_enter_all
qemu_co_queue_restart_all is basically the same as qemu_co_enter_all but without a QemuLockable argument. That's perfectly fine, but only as long as the function is marked coroutine_fn. If used outside coroutine context, qemu_co_queue_wait will attempt to take the lock and that is just broken: if you are calling qemu_co_queue_restart_all outside coroutine context, the lock is going to be a QemuMutex which cannot be taken twice by the same thread. The patch adds the marker to qemu_co_queue_restart_all and to its sole non-coroutine_fn caller; it then reimplements the function in terms of qemu_co_enter_all_impl, to remove duplicated code and to clarify that the latter also works in coroutine context. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20220427130830.150180-4-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
d6ee15adec
commit
f0d43b1ece
3 changed files with 11 additions and 19 deletions
|
@ -67,21 +67,6 @@ void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock)
|
|||
}
|
||||
}
|
||||
|
||||
void qemu_co_queue_restart_all(CoQueue *queue)
|
||||
{
|
||||
Coroutine *next;
|
||||
|
||||
if (QSIMPLEQ_EMPTY(&queue->entries)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((next = QSIMPLEQ_FIRST(&queue->entries)) != NULL) {
|
||||
QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
|
||||
aio_co_wake(next);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool qemu_co_enter_next_impl(CoQueue *queue, QemuLockable *lock)
|
||||
{
|
||||
Coroutine *next;
|
||||
|
@ -115,6 +100,12 @@ void qemu_co_enter_all_impl(CoQueue *queue, QemuLockable *lock)
|
|||
}
|
||||
}
|
||||
|
||||
void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue)
|
||||
{
|
||||
/* No unlock/lock needed in coroutine context. */
|
||||
qemu_co_enter_all_impl(queue, NULL);
|
||||
}
|
||||
|
||||
bool qemu_co_queue_empty(CoQueue *queue)
|
||||
{
|
||||
return QSIMPLEQ_FIRST(&queue->entries) == NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue