From patchwork Fri Apr 15 14:23:44 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: 8851491 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 99118BF29F for ; Fri, 15 Apr 2016 14:27:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2B31A2037C for ; Fri, 15 Apr 2016 14:27:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 841F320374 for ; Fri, 15 Apr 2016 14:27:40 +0000 (UTC) Received: from localhost ([::1]:35163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4ih-00088y-Sv for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Apr 2016 10:27:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4f7-0000OI-El for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:23:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar4f6-0007e2-Is for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:23:57 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:38341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4f6-0007di-Bj for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:23:56 -0400 Received: by mail-wm0-x22d.google.com with SMTP id u206so34789799wme.1 for ; Fri, 15 Apr 2016 07:23:56 -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=AcSBoe0Fgdph3P6TtuZMFn6MxN8dBe5I4uL+QQdH7J4=; b=hzR2VqJSnoEw7dMe7EhxMHnT9+8LDusR+dcMn/c5QSyg3l5GXrJevGxAQ2MGEIr936 FiEm1ZCJ4//YUWfQlyz29IfT/KC5YNJpeLiOkucJtJJHANemU8bni5Aa7jwsoUN9pYio 0Sk7qjOBKXJqaEy2XBCSyFeHi+TG4824fAls0= 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=AcSBoe0Fgdph3P6TtuZMFn6MxN8dBe5I4uL+QQdH7J4=; b=V0+31jueJd8nT/Qa3655a2RZcg/d/j4bC98udxSavntFZblutSPmno/zCUJeBKayo4 jjNbgdJBuM+vWlqwpJ72Qx4KvwWTXsC6de3Y7Mi8LxqxHx2n+YE8woKtULlvpfF5bd3D fcrgETzymu3gCW8zRA0dWv+nkri5VzfTWSZ1CDd9Ausohj70sVVc7h1NmO0HhZt72gTm Az4+MSrE4ZBQC7cYJfTOI3Fu6ZiGEUkrSY1MBz+OVAQru39LsGPHMKy7Vf4dWJc3iO0K sZzrqMSmnoOE9tamTkglgMJ2mL7DKcdaMMHfOshii6jcAlGG/sIqyUpFqWNUsfoTr2fN CIkQ== X-Gm-Message-State: AOPr4FVZQwtdBw7bz0EqHGMgN7wBTXNMIGqSxkTUbwJkjVExnw5KYAHYzhzMJ5Aexi2qFCB9 X-Received: by 10.28.189.10 with SMTP id n10mr4924113wmf.101.1460730235803; Fri, 15 Apr 2016 07:23:55 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id fu9sm37906878wjb.44.2016.04.15.07.23.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Apr 2016 07:23:53 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B48CF3E056A; Fri, 15 Apr 2016 15:24:04 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Date: Fri, 15 Apr 2016 15:23:44 +0100 Message-Id: <1460730231-1184-7-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1460730231-1184-1-git-send-email-alex.bennee@linaro.org> References: <1460730231-1184-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::22d Subject: [Qemu-devel] [RFC v1 05/12] 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, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This allows for slightly neater code when checking for success of a cmpxchg operation. Signed-off-by: Alex Bennée --- include/qemu/atomic.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 5dba7db..94e7110 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -123,6 +123,16 @@ _old; \ }) +#define atomic_bool_cmpxchg(ptr, old, new) \ + ({ \ + typeof(*ptr) _old = (old), _new = (new); \ + bool r; \ + r = __atomic_compare_exchange(ptr, &_old, &_new, false, \ + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ + r; \ + }) + + /* 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) @@ -327,6 +337,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)