From patchwork Fri Sep 12 12:48:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lionel Landwerlin X-Patchwork-Id: 4894471 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1FE8CBEEA5 for ; Fri, 12 Sep 2014 12:48:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C456720266 for ; Fri, 12 Sep 2014 12:48:54 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3E9452012B for ; Fri, 12 Sep 2014 12:48:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD16A6E6B3; Fri, 12 Sep 2014 05:48:48 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F84E6E6B3 for ; Fri, 12 Sep 2014 05:48:47 -0700 (PDT) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by orsmga102.jf.intel.com with ESMTP; 12 Sep 2014 05:42:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,513,1406617200"; d="scan'208";a="477113636" Received: from unknown (HELO ivy.amr.corp.intel.com) ([10.255.12.173]) by azsmga001.ch.intel.com with ESMTP; 12 Sep 2014 05:48:42 -0700 From: Lionel Landwerlin To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/4] atomic: add atomic_add_unless() Date: Fri, 12 Sep 2014 13:48:35 +0100 Message-Id: <1410526118-8421-2-git-send-email-lionel.g.landwerlin@intel.com> X-Mailer: git-send-email 2.0.1 In-Reply-To: <1410526118-8421-1-git-send-email-lionel.g.landwerlin@intel.com> References: <1410526118-8421-1-git-send-email-lionel.g.landwerlin@intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Signed-off-by: Lionel Landwerlin --- xf86atomic.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xf86atomic.h b/xf86atomic.h index db2f619..bc482c9 100644 --- a/xf86atomic.h +++ b/xf86atomic.h @@ -96,4 +96,13 @@ typedef struct { uint_t atomic; } atomic_t; #error libdrm requires atomic operations, please define them for your CPU/compiler. #endif +static inline int atomic_add_unless(atomic_t *v, int add, int unless) +{ + int c, old; + c = atomic_read(v); + while (c != unless && (old = atomic_cmpxchg(v, c, c + add)) != c) + c = old; + return c == unless; +} + #endif