mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-27 03:51:57 -06:00
coroutine-lock: qemu_co_queue_next is a coroutine-only qemu_co_enter_next
qemu_co_queue_next is basically the same as qemu_co_enter_next 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_next 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 and reimplements qemu_co_queue_next in terms of qemu_co_enter_next_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-2-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
bf2f69d08b
commit
248af9e80a
2 changed files with 11 additions and 17 deletions
|
@ -208,11 +208,12 @@ void qemu_co_queue_init(CoQueue *queue);
|
|||
void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock);
|
||||
|
||||
/**
|
||||
* Removes the next coroutine from the CoQueue, and wake it up.
|
||||
* Removes the next coroutine from the CoQueue, and queue it to run after
|
||||
* the currently-running coroutine yields.
|
||||
* Returns true if a coroutine was removed, false if the queue is empty.
|
||||
* OK to run from coroutine and non-coroutine context.
|
||||
* Used from coroutine context, use qemu_co_enter_next outside.
|
||||
*/
|
||||
bool qemu_co_queue_next(CoQueue *queue);
|
||||
bool coroutine_fn qemu_co_queue_next(CoQueue *queue);
|
||||
|
||||
/**
|
||||
* Empties the CoQueue; all coroutines are woken up.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue