Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757157AbcCXOkM (ORCPT ); Thu, 24 Mar 2016 10:40:12 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:33271 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755924AbcCXOio (ORCPT ); Thu, 24 Mar 2016 10:38:44 -0400 From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Andrew Morton Subject: [PATCH 1/3] atomic: Introduce atomic_fetch_or Date: Thu, 24 Mar 2016 15:37:59 +0100 Message-Id: <1458830281-4255-2-git-send-email-fweisbec@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1458830281-4255-1-git-send-email-fweisbec@gmail.com> References: <1458830281-4255-1-git-send-email-fweisbec@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1481 Lines: 52 This is deemed to replace the type generic fetch_or() which brings a lot of issues such as macro induced block variable aliasing and sloppy types. Not to mention fetch_or() doesn't refer to any namespace, adding even more confusion. So lets provide an atomic_t version. Current and next users of fetch_or are thus encouraged to use atomic_t. Cc: Andrew Morton Cc: Ingo Molnar Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Frederic Weisbecker --- include/linux/atomic.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/atomic.h b/include/linux/atomic.h index df4f369..3d64c08 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -559,6 +559,27 @@ static inline int atomic_dec_if_positive(atomic_t *v) #endif /** + * atomic_fetch_or - perform *p |= mask and return old value of *p + * @p: pointer to atomic_t + * @mask: mask to OR on the atomic_t + */ +#ifndef atomic_fetch_or +static inline int atomic_fetch_or(atomic_t *p, int mask) +{ + int old, val = atomic_read(p); + + for (;;) { + old = atomic_cmpxchg(p, val, val | mask); + if (old == val) + break; + val = old; + } + + return old; +} +#endif + +/** * fetch_or - perform *ptr |= mask and return old value of *ptr * @ptr: pointer to value * @mask: mask to OR on the value -- 2.7.0