提交 bd451435 编写于 作者: P Paolo Bonzini 提交者: Stefan Hajnoczi

async: remove unnecessary inc/dec pairs

Pull the increment/decrement pair out of aio_bh_poll and into the
callers.
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: NFam Zheng <famz@redhat.com>
Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
Message-id: 20170213135235.12274-18-pbonzini@redhat.com
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
上级 a153bf52
...@@ -425,9 +425,8 @@ static bool aio_dispatch_handlers(AioContext *ctx) ...@@ -425,9 +425,8 @@ static bool aio_dispatch_handlers(AioContext *ctx)
void aio_dispatch(AioContext *ctx) void aio_dispatch(AioContext *ctx)
{ {
aio_bh_poll(ctx);
qemu_lockcnt_inc(&ctx->list_lock); qemu_lockcnt_inc(&ctx->list_lock);
aio_bh_poll(ctx);
aio_dispatch_handlers(ctx); aio_dispatch_handlers(ctx);
qemu_lockcnt_dec(&ctx->list_lock); qemu_lockcnt_dec(&ctx->list_lock);
...@@ -679,16 +678,15 @@ bool aio_poll(AioContext *ctx, bool blocking) ...@@ -679,16 +678,15 @@ bool aio_poll(AioContext *ctx, bool blocking)
} }
npfd = 0; npfd = 0;
qemu_lockcnt_dec(&ctx->list_lock);
progress |= aio_bh_poll(ctx); progress |= aio_bh_poll(ctx);
if (ret > 0) { if (ret > 0) {
qemu_lockcnt_inc(&ctx->list_lock);
progress |= aio_dispatch_handlers(ctx); progress |= aio_dispatch_handlers(ctx);
qemu_lockcnt_dec(&ctx->list_lock);
} }
qemu_lockcnt_dec(&ctx->list_lock);
progress |= timerlistgroup_run_timers(&ctx->tlg); progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress; return progress;
......
...@@ -253,8 +253,6 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) ...@@ -253,8 +253,6 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
bool progress = false; bool progress = false;
AioHandler *tmp; AioHandler *tmp;
qemu_lockcnt_inc(&ctx->list_lock);
/* /*
* We have to walk very carefully in case aio_set_fd_handler is * We have to walk very carefully in case aio_set_fd_handler is
* called while we're walking. * called while we're walking.
...@@ -305,14 +303,15 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) ...@@ -305,14 +303,15 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
} }
} }
qemu_lockcnt_dec(&ctx->list_lock);
return progress; return progress;
} }
void aio_dispatch(AioContext *ctx) void aio_dispatch(AioContext *ctx)
{ {
qemu_lockcnt_inc(&ctx->list_lock);
aio_bh_poll(ctx); aio_bh_poll(ctx);
aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE); aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
qemu_lockcnt_dec(&ctx->list_lock);
timerlistgroup_run_timers(&ctx->tlg); timerlistgroup_run_timers(&ctx->tlg);
} }
...@@ -349,7 +348,6 @@ bool aio_poll(AioContext *ctx, bool blocking) ...@@ -349,7 +348,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
} }
} }
qemu_lockcnt_dec(&ctx->list_lock);
first = true; first = true;
/* ctx->notifier is always registered. */ /* ctx->notifier is always registered. */
...@@ -392,6 +390,8 @@ bool aio_poll(AioContext *ctx, bool blocking) ...@@ -392,6 +390,8 @@ bool aio_poll(AioContext *ctx, bool blocking)
progress |= aio_dispatch_handlers(ctx, event); progress |= aio_dispatch_handlers(ctx, event);
} while (count > 0); } while (count > 0);
qemu_lockcnt_dec(&ctx->list_lock);
progress |= timerlistgroup_run_timers(&ctx->tlg); progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress; return progress;
} }
......
...@@ -90,15 +90,16 @@ void aio_bh_call(QEMUBH *bh) ...@@ -90,15 +90,16 @@ void aio_bh_call(QEMUBH *bh)
bh->cb(bh->opaque); bh->cb(bh->opaque);
} }
/* Multiple occurrences of aio_bh_poll cannot be called concurrently */ /* Multiple occurrences of aio_bh_poll cannot be called concurrently.
* The count in ctx->list_lock is incremented before the call, and is
* not affected by the call.
*/
int aio_bh_poll(AioContext *ctx) int aio_bh_poll(AioContext *ctx)
{ {
QEMUBH *bh, **bhp, *next; QEMUBH *bh, **bhp, *next;
int ret; int ret;
bool deleted = false; bool deleted = false;
qemu_lockcnt_inc(&ctx->list_lock);
ret = 0; ret = 0;
for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) { for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) {
next = atomic_rcu_read(&bh->next); next = atomic_rcu_read(&bh->next);
...@@ -123,11 +124,10 @@ int aio_bh_poll(AioContext *ctx) ...@@ -123,11 +124,10 @@ int aio_bh_poll(AioContext *ctx)
/* remove deleted bhs */ /* remove deleted bhs */
if (!deleted) { if (!deleted) {
qemu_lockcnt_dec(&ctx->list_lock);
return ret; return ret;
} }
if (qemu_lockcnt_dec_and_lock(&ctx->list_lock)) { if (qemu_lockcnt_dec_if_lock(&ctx->list_lock)) {
bhp = &ctx->first_bh; bhp = &ctx->first_bh;
while (*bhp) { while (*bhp) {
bh = *bhp; bh = *bhp;
...@@ -138,7 +138,7 @@ int aio_bh_poll(AioContext *ctx) ...@@ -138,7 +138,7 @@ int aio_bh_poll(AioContext *ctx)
bhp = &bh->next; bhp = &bh->next;
} }
} }
qemu_lockcnt_unlock(&ctx->list_lock); qemu_lockcnt_inc_and_unlock(&ctx->list_lock);
} }
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册