From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24487 invoked by alias); 25 Jan 2007 18:16:57 -0000 Received: (qmail 24459 invoked by uid 22791); 25 Jan 2007 18:16:55 -0000 X-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,FORGED_RCVD_HELO X-Spam-Check-By: sourceware.org Received: from tomts25.bellnexxia.net (HELO tomts25-srv.bellnexxia.net) (209.226.175.188) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 25 Jan 2007 18:16:47 +0000 Received: from krystal.dyndns.org ([67.68.204.133]) by tomts25-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20070125181645.QTFT6280.tomts25-srv.bellnexxia.net@krystal.dyndns.org> for ; Thu, 25 Jan 2007 13:16:45 -0500 Received: from localhost (localhost [127.0.0.1]) (uid 1000) by krystal.dyndns.org with local; Thu, 25 Jan 2007 11:15:56 -0500 id 001832D0.45B8D7BC.0000497F From: Mathieu Desnoyers To: linux-kernel@vger.kernel.org Cc: Linus Torvalds , Andrew Morton , Ingo Molnar , Greg Kroah-Hartman , Christoph Hellwig , ltt-dev@shafik.org, systemtap@sources.redhat.com, Douglas Niehaus , "Martin J. Bligh" , Thomas Gleixner , Paul Mackerras , Mathieu Desnoyers Subject: [PATCH 05/09] atomic.h : Add atomic64 cmpxchg, xchg and add_unless to mips Date: Thu, 25 Jan 2007 18:16:00 -0000 Message-Id: <1169741756845-git-send-email-mathieu.desnoyers@polymtl.ca> X-Mailer: git-send-email 1.4.4.3 In-Reply-To: <11697417541743-git-send-email-mathieu.desnoyers@polymtl.ca> References: <11697417541743-git-send-email-mathieu.desnoyers@polymtl.ca> X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2007-q1/txt/msg00220.txt.bz2 atomic.h : Add atomic64 cmpxchg, xchg and add_unless to mips Signed-off-by: Mathieu Desnoyers --- a/include/asm-mips/atomic.h +++ b/include/asm-mips/atomic.h @@ -291,8 +291,9 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) return result; } -#define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n))) -#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) +#define atomic_cmpxchg(v, o, n) \ + (((__typeof__((v)->counter)))cmpxchg(&((v)->counter), (o), (n))) +#define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) /** * atomic_add_unless - add unless the number is a given value @@ -305,7 +306,7 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) */ #define atomic_add_unless(v, a, u) \ ({ \ - int c, old; \ + __typeof__((v)->counter) c, old; \ c = atomic_read(v); \ while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \ c = old; \ @@ -651,6 +652,29 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v) return result; } +#define atomic64_cmpxchg(v, o, n) \ + (((__typeof__((v)->counter)))cmpxchg(&((v)->counter), (o), (n))) +#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new))) + +/** + * atomic64_add_unless - add unless the number is a given value + * @v: pointer of type atomic64_t + * @a: the amount to add to v... + * @u: ...unless v is equal to u. + * + * Atomically adds @a to @v, so long as it was not @u. + * Returns non-zero if @v was not @u, and zero otherwise. + */ +#define atomic64_add_unless(v, a, u) \ +({ \ + __typeof__((v)->counter) c, old; \ + c = atomic_read(v); \ + while (c != (u) && (old = atomic64_cmpxchg((v), c, c + (a))) != c) \ + c = old; \ + c != (u); \ +}) +#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) + #define atomic64_dec_return(v) atomic64_sub_return(1,(v)) #define atomic64_inc_return(v) atomic64_add_return(1,(v))