From patchwork Thu Aug 11 15:24:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 73784 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp179671qga; Thu, 11 Aug 2016 08:58:03 -0700 (PDT) X-Received: by 10.55.195.139 with SMTP id r11mr11363050qkl.22.1470931083518; Thu, 11 Aug 2016 08:58:03 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u128si598113qkc.250.2016.08.11.08.58.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 11 Aug 2016 08:58:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXsMt-0004vW-2B for patch@linaro.org; Thu, 11 Aug 2016 11:58:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXrwX-0001zr-JV for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:30:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXrwV-0007sW-Fa for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:30:48 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:36621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXrwV-0007sP-6Z for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:30:47 -0400 Received: by mail-wm0-x234.google.com with SMTP id q128so7381428wma.1 for ; Thu, 11 Aug 2016 08:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WH1D3xaG8WS/KrjKQvVV1AUs56cX0nJGmVy8rRUbf/k=; b=RG7Fp7QvD32w0uOc6hvOZEMwCwZGNAh9WoKe4re1YHJlhePye0m4a9VGx5qokHQRLM X2xnd1BELHtdAALEcKSnU542EsjNIcL36rDtCn7I8LK8lxbh3Vt3tUdGLokKYNu1x+XC 2aXulynKw5qvOsnAgT8bXdeElLD3WPQ3rvUz4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WH1D3xaG8WS/KrjKQvVV1AUs56cX0nJGmVy8rRUbf/k=; b=aM+C1XV4WgEbIlw4ipfk51RMfe7I9I9GjvToCn9B0lrWeu46rNTfsq0viHFthxMX1l 4L+KWBAZextNxJrTcPbwhAf9wdTeXfkleSaAtiMrl819j/g+fdfV2CWr0pmsyjAiKfz1 8D+hoRRERx3NW+NyYKg4jCnq2wIJUxiBormSAsvEaOxEyms5Ouf9/lLthV5BOdW6nUNm Fi59tbHYZ8/1t/mdvTNylKfKLJoUUywz+BdRuzAqBo/jx6w0MI/1t9aPr7NZE+HSI7hY s48ZC6ZC3OGhUzBlz0KZFUoaHObMyCALmvb09wVaaNEJ0S96nFJLix89XLEzveZdeX8P 19lw== X-Gm-Message-State: AEkoousamSQJXQeS0hkx0ph+XuJ8ZchII6cvmuvhcdfP9ItgCfwhCvEGPUUmDknt5sBI0uPY X-Received: by 10.28.155.212 with SMTP id d203mr10085163wme.103.1470929446484; Thu, 11 Aug 2016 08:30:46 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a184sm424179wmh.1.2016.08.11.08.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 08:30:43 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 9287F3E0349; Thu, 11 Aug 2016 16:24:31 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, qemu-devel@nongnu.org, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, bobby.prani@gmail.com, nikunj@linux.vnet.ibm.com Date: Thu, 11 Aug 2016 16:24:19 +0100 Message-Id: <1470929064-4092-24-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470929064-4092-1-git-send-email-alex.bennee@linaro.org> References: <1470929064-4092-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [RFC v4 23/28] atomic: introduce cmpxchg_bool 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: peter.maydell@linaro.org, claudio.fontana@huawei.com, jan.kiszka@siemens.com, mark.burton@greensocs.com, serge.fdrv@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows for slightly neater code when checking for success of a cmpxchg operation. Signed-off-by: Alex Bennée --- v4 (base-patches) - brought forward from ARM enabling patches - remove the un-needed extra temps --- include/qemu/atomic.h | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.4 diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 560b1af..aba2c23 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -152,6 +152,14 @@ _old; \ }) +#define atomic_bool_cmpxchg(ptr, old, new) \ + ({ \ + typeof(*ptr) _old = (old), _new = (new); \ + __atomic_compare_exchange(ptr, &_old, &_new, false, \ + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ + }) + + /* Provide shorter names for GCC atomic builtins, return old value */ #define atomic_fetch_inc(ptr) __atomic_fetch_add(ptr, 1, __ATOMIC_SEQ_CST) #define atomic_fetch_dec(ptr) __atomic_fetch_sub(ptr, 1, __ATOMIC_SEQ_CST) @@ -356,6 +364,7 @@ #define atomic_fetch_and __sync_fetch_and_and #define atomic_fetch_or __sync_fetch_and_or #define atomic_cmpxchg __sync_val_compare_and_swap +#define atomic_bool_cmpxchg __sync_bool_compare_and_swap #define atomic_dec_fetch(ptr) __sync_sub_and_fetch(ptr, 1)