Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030218AbVLSBg1 (ORCPT ); Sun, 18 Dec 2005 20:36:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1030222AbVLSBfy (ORCPT ); Sun, 18 Dec 2005 20:35:54 -0500 Received: from mx3.mail.elte.hu ([157.181.1.138]:19431 "EHLO mx3.mail.elte.hu") by vger.kernel.org with ESMTP id S1030218AbVLSBfv (ORCPT ); Sun, 18 Dec 2005 20:35:51 -0500 Date: Mon, 19 Dec 2005 02:35:08 +0100 From: Ingo Molnar To: linux-kernel@vger.kernel.org, Linus Torvalds , Andrew Morton Cc: Arjan van de Ven , Steven Rostedt , Alan Cox , Christoph Hellwig , Andi Kleen , David Howells , Alexander Viro , Oleg Nesterov , Paul Jackson Subject: [patch 04/15] Generic Mutex Subsystem, add-atomic-call-func-x86_64.patch Message-ID: <20051219013507.GE27658@elte.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-ELTE-SpamScore: 0.0 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=0.0 required=5.9 tests=AWL autolearn=no SpamAssassin version=3.0.3 0.0 AWL AWL: From: address is in the auto white-list X-ELTE-VirusStatus: clean Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2660 Lines: 84 add two new atomic ops to x86_64: atomic_dec_call_if_negative() and atomic_inc_call_if_nonpositive(), which are conditional-call-if atomic operations. Needed by the new mutex code. Signed-off-by: Ingo Molnar ---- include/asm-x86_64/atomic.h | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+) Index: linux/include/asm-x86_64/atomic.h =================================================================== --- linux.orig/include/asm-x86_64/atomic.h +++ linux/include/asm-x86_64/atomic.h @@ -203,6 +203,62 @@ static __inline__ int atomic_sub_return( #define atomic_inc_return(v) (atomic_add_return(1,v)) #define atomic_dec_return(v) (atomic_sub_return(1,v)) +/** + * atomic_dec_call_if_negative - decrement and call function if negative + * @v: pointer of type atomic_t + * @fn: function to call if the result is negative + * + * Atomically decrements @v and calls a function if the result is negative. + * NOTE: the function is type-checked and must be a fastcall. + */ +#define atomic_dec_call_if_negative(v, fn_name) \ +do { \ + fastcall void (*__tmp)(atomic_t *) = fn_name; \ + \ + (void)__tmp; \ + typecheck(atomic_t *, v); \ + \ + __asm__ __volatile__( \ + LOCK "decl (%%rdi)\n" \ + "js 2f\n" \ + "1:\n" \ + LOCK_SECTION_START("") \ + "2: call "#fn_name"\n\t" \ + "jmp 1b\n" \ + LOCK_SECTION_END \ + : \ + :"D" (v) \ + :"memory"); \ +} while (0) + +/** + * atomic_inc_call_if_nonpositive - increment and call function if nonpositive + * @v: pointer of type atomic_t + * @fn: function to call if the result is nonpositive + * + * Atomically increments @v and calls a function if the result is nonpositive. + * NOTE: the function is type-checked and must be a fastcall. + */ +#define atomic_inc_call_if_nonpositive(v, fn_name) \ +do { \ + fastcall void (*__tmp)(atomic_t *) = fn_name; \ + \ + (void)__tmp; \ + typecheck(atomic_t *, v); \ + \ + __asm__ __volatile__( \ + LOCK "incl (%%rdi)\n" \ + "jle 2f\n" \ + "1:\n" \ + LOCK_SECTION_START("") \ + "2: call "#fn_name"\n\t" \ + "jmp 1b\n" \ + LOCK_SECTION_END \ + : \ + :"D" (v) \ + :"memory"); \ +} while (0) + /* An 64bit atomic type */ typedef struct { volatile long counter; } atomic64_t; - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/