All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 04/15] Generic Mutex Subsystem, add-atomic-call-func-x86_64.patch
@ 2005-12-19  1:35 Ingo Molnar
  2005-12-19 17:49 ` Zwane Mwaikambo
  0 siblings, 1 reply; 34+ messages in thread
From: Ingo Molnar @ 2005-12-19  1:35 UTC (permalink / raw)
  To: linux-kernel, 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


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 <mingo@elte.hu>

----

 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;

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2005-12-21 11:59 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-19  1:35 [patch 04/15] Generic Mutex Subsystem, add-atomic-call-func-x86_64.patch Ingo Molnar
2005-12-19 17:49 ` Zwane Mwaikambo
2005-12-19 20:58   ` David Woodhouse
2005-12-20  4:31     ` Ingo Molnar
2005-12-20  6:30       ` Nicolas Pitre
2005-12-20  8:12         ` Nick Piggin
2005-12-20 14:10           ` Nicolas Pitre
2005-12-20 14:12             ` Nick Piggin
2005-12-20 14:35               ` Nicolas Pitre
2005-12-20 15:05                 ` Nick Piggin
2005-12-20 16:35                   ` Nicolas Pitre
2005-12-20 19:20                     ` Russell King
2005-12-20 19:32                       ` Arjan van de Ven
2005-12-20 19:37                         ` Russell King
2005-12-20 19:59                         ` Nicolas Pitre
2005-12-20 19:43                       ` Steven Rostedt
2005-12-20 19:57                         ` Russell King
2005-12-20 20:35                         ` Horst von Brand
2005-12-20 19:55                       ` Nicolas Pitre
2005-12-20 18:27                 ` Linus Torvalds
2005-12-20 19:34                   ` Russell King
2005-12-20 20:10                     ` Linus Torvalds
2005-12-20 21:18                       ` Nicolas Pitre
2005-12-20 22:04                         ` Linus Torvalds
2005-12-20 22:19                           ` Steven Rostedt
2005-12-20 22:43                           ` Nicolas Pitre
2005-12-21  6:00                           ` Ingo Molnar
2005-12-21  2:12                         ` Nick Piggin
2005-12-20 19:49                   ` Nicolas Pitre
2005-12-20 18:25               ` Linus Torvalds
2005-12-21  6:20               ` Ingo Molnar
2005-12-21  4:16         ` Nicolas Pitre
2005-12-21  6:26           ` Ingo Molnar
2005-12-20  4:29   ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.