From patchwork Mon Nov 6 09:46:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 834549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVntZ0kWTz9s7p for ; Mon, 6 Nov 2017 20:53:10 +1100 (AEDT) Received: from localhost ([::1]:47197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBe5c-0007lE-4c for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 04:53:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBe2l-0005rb-OK for qemu-devel@nongnu.org; Mon, 06 Nov 2017 04:50:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBe2g-0004pN-Qb for qemu-devel@nongnu.org; Mon, 06 Nov 2017 04:50:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBe2g-0004pC-KZ for qemu-devel@nongnu.org; Mon, 06 Nov 2017 04:50:06 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96D0FC04AC4D; Mon, 6 Nov 2017 09:50:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96D0FC04AC4D Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com Received: from pxdev.xzpeter.org.com (ovpn-12-165.pek2.redhat.com [10.72.12.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D47F6A02C; Mon, 6 Nov 2017 09:49:53 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 6 Nov 2017 17:46:32 +0800 Message-Id: <20171106094643.14881-17-peterx@redhat.com> In-Reply-To: <20171106094643.14881-1-peterx@redhat.com> References: <20171106094643.14881-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Nov 2017 09:50:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v3 16/27] monitor: let monitor_{suspend|resume} thread safe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , Jiri Denemark , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Monitor code now can be run in more than one thread. Let the suspend and resume code for thread safety. Reviewed-by: Fam Zheng --- monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index 1e87de87f8..47e969244d 100644 --- a/monitor.c +++ b/monitor.c @@ -4003,7 +4003,7 @@ int monitor_suspend(Monitor *mon) { if (!mon->rs) return -ENOTTY; - mon->suspend_cnt++; + atomic_inc(&mon->suspend_cnt); return 0; } @@ -4011,7 +4011,7 @@ void monitor_resume(Monitor *mon) { if (!mon->rs) return; - if (--mon->suspend_cnt == 0) + if (atomic_dec_fetch(&mon->suspend_cnt) == 0) readline_show_prompt(mon->rs); }