From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIw3j-0001f4-Uy for qemu-devel@nongnu.org; Thu, 08 Jun 2017 07:57:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIw3f-0001r2-3l for qemu-devel@nongnu.org; Thu, 08 Jun 2017 07:57:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIw3e-0001qg-U8 for qemu-devel@nongnu.org; Thu, 08 Jun 2017 07:56:59 -0400 From: Fam Zheng Date: Thu, 8 Jun 2017 19:56:26 +0800 Message-Id: <20170608115643.18859-7-famz@redhat.com> In-Reply-To: <20170608115643.18859-1-famz@redhat.com> References: <20170608115643.18859-1-famz@redhat.com> Subject: [Qemu-devel] [PULL v3 06/23] block: access quiesce_counter with atomic ops List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Signed-off-by: Paolo Bonzini Message-Id: <20170605123908.18777-3-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/io.c | 4 ++-- include/block/block_int.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 98c690f..70643df 100644 --- a/block/io.c +++ b/block/io.c @@ -241,7 +241,7 @@ void bdrv_drained_begin(BlockDriverState *bs) return; } - if (!bs->quiesce_counter++) { + if (atomic_fetch_inc(&bs->quiesce_counter) == 0) { aio_disable_external(bdrv_get_aio_context(bs)); bdrv_parent_drained_begin(bs); } @@ -252,7 +252,7 @@ void bdrv_drained_begin(BlockDriverState *bs) void bdrv_drained_end(BlockDriverState *bs) { assert(bs->quiesce_counter > 0); - if (--bs->quiesce_counter > 0) { + if (atomic_fetch_dec(&bs->quiesce_counter) > 1) { return; } diff --git a/include/block/block_int.h b/include/block/block_int.h index 49f2ebb..1824e0e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -637,6 +637,7 @@ struct BlockDriverState { /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; + /* Accessed with atomic ops. */ int quiesce_counter; }; -- 2.9.4