mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
thread-pool: use ThreadPool from the running thread
Use qemu_get_current_aio_context() where possible, since we always submit work to the current thread anyways. We want to also be sure that the thread submitting the work is the same as the one processing the pool, to avoid adding synchronization to the pool list. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Message-Id: <20230203131731.851116-4-eesposit@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
a75e4e4365
commit
0fdb73112b
5 changed files with 21 additions and 18 deletions
|
@ -48,7 +48,7 @@ struct ThreadPoolElement {
|
|||
/* Access to this list is protected by lock. */
|
||||
QTAILQ_ENTRY(ThreadPoolElement) reqs;
|
||||
|
||||
/* Access to this list is protected by the global mutex. */
|
||||
/* This list is only written by the thread pool's mother thread. */
|
||||
QLIST_ENTRY(ThreadPoolElement) all;
|
||||
};
|
||||
|
||||
|
@ -175,7 +175,6 @@ static void thread_pool_completion_bh(void *opaque)
|
|||
ThreadPool *pool = opaque;
|
||||
ThreadPoolElement *elem, *next;
|
||||
|
||||
aio_context_acquire(pool->ctx);
|
||||
restart:
|
||||
QLIST_FOREACH_SAFE(elem, &pool->head, all, next) {
|
||||
if (elem->state != THREAD_DONE) {
|
||||
|
@ -195,9 +194,7 @@ restart:
|
|||
*/
|
||||
qemu_bh_schedule(pool->completion_bh);
|
||||
|
||||
aio_context_release(pool->ctx);
|
||||
elem->common.cb(elem->common.opaque, elem->ret);
|
||||
aio_context_acquire(pool->ctx);
|
||||
|
||||
/* We can safely cancel the completion_bh here regardless of someone
|
||||
* else having scheduled it meanwhile because we reenter the
|
||||
|
@ -211,7 +208,6 @@ restart:
|
|||
qemu_aio_unref(elem);
|
||||
}
|
||||
}
|
||||
aio_context_release(pool->ctx);
|
||||
}
|
||||
|
||||
static void thread_pool_cancel(BlockAIOCB *acb)
|
||||
|
@ -251,6 +247,9 @@ BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool,
|
|||
{
|
||||
ThreadPoolElement *req;
|
||||
|
||||
/* Assert that the thread submitting work is the same running the pool */
|
||||
assert(pool->ctx == qemu_get_current_aio_context());
|
||||
|
||||
req = qemu_aio_get(&thread_pool_aiocb_info, NULL, cb, opaque);
|
||||
req->func = func;
|
||||
req->arg = arg;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue