diff --git a/async.c b/async.c index 5b6fe6b..5aa9982 100644 --- a/async.c +++ b/async.c @@ -40,6 +40,18 @@ struct QEMUBH { bool deleted; }; +static __thread AioContext *my_ctx = NULL; + +AioContext *get_current_aio_context(void) +{ + return my_ctx; +} + +void set_current_aio_context(AioContext *ctx) +{ + my_ctx = ctx; +} + QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) { QEMUBH *bh; @@ -131,7 +143,9 @@ void qemu_bh_schedule(QEMUBH *bh) */ smp_mb(); bh->scheduled = 1; - aio_notify(ctx); + + if (get_current_aio_context() != ctx) + aio_notify(ctx); } diff --git a/include/block/aio.h b/include/block/aio.h index a92511b..29f29e2 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -307,4 +307,7 @@ static inline void aio_timer_init(AioContext *ctx, timer_init(ts, ctx->tlg.tl[type], scale, cb, opaque); } +AioContext *get_current_aio_context(void); +void set_current_aio_context(AioContext *ctx); + #endif diff --git a/iothread.c b/iothread.c index 1fbf9f1..beb32ad 100644 --- a/iothread.c +++ b/iothread.c @@ -36,6 +36,8 @@ static void *iothread_run(void *opaque) qemu_cond_signal(&iothread->init_done_cond); qemu_mutex_unlock(&iothread->init_done_lock); + set_current_aio_context(iothread->ctx); + while (!iothread->stopping) { aio_context_acquire(iothread->ctx); while (!iothread->stopping && aio_poll(iothread->ctx, true)) {