[CRIU] [PATCH 1/2] zdtm/lock: add futex_add_and_wake and futex_wait_while_lt

Andrey Vagin avagin at openvz.org
Tue Feb 25 06:04:17 PST 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/lib/arch/arm/include/asm/atomic.h |  2 ++
 test/zdtm/lib/arch/x86/include/asm/atomic.h |  7 +++++++
 test/zdtm/lib/lock.h                        | 18 ++++++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/test/zdtm/lib/arch/arm/include/asm/atomic.h b/test/zdtm/lib/arch/arm/include/asm/atomic.h
index 6d91ceb..bcf3fe3 100644
--- a/test/zdtm/lib/arch/arm/include/asm/atomic.h
+++ b/test/zdtm/lib/arch/arm/include/asm/atomic.h
@@ -58,6 +58,8 @@ static inline unsigned int atomic_sub_return(int i, atomic_t *v)
 
 static inline unsigned int atomic_inc(atomic_t *v) { return atomic_add_return(1, v) - 1; }
 
+static inline unsigned int atomic_add(int val, atomic_t *v) { return atomic_add_return(val, v) - val; }
+
 static inline unsigned int atomic_dec(atomic_t *v) { return atomic_sub_return(1, v) + 1; }
 
 /* true if the result is 0, or false for all other cases. */
diff --git a/test/zdtm/lib/arch/x86/include/asm/atomic.h b/test/zdtm/lib/arch/x86/include/asm/atomic.h
index 3debc48..7621df0 100644
--- a/test/zdtm/lib/arch/x86/include/asm/atomic.h
+++ b/test/zdtm/lib/arch/x86/include/asm/atomic.h
@@ -39,4 +39,11 @@
 		ret__;						\
 	})
 
+#define atomic_add(i, mem)					\
+({								\
+	asm volatile("lock addl %1,%0"				\
+		     : "+m" (*mem)				\
+		     : "ir" (i));				\
+})
+
 #endif /* ATOMIC_H__ */
diff --git a/test/zdtm/lib/lock.h b/test/zdtm/lib/lock.h
index eb03990..362de49 100644
--- a/test/zdtm/lib/lock.h
+++ b/test/zdtm/lib/lock.h
@@ -41,6 +41,14 @@ static inline void futex_set(futex_t *f, uint32_t v)
 	atomic_set(&f->raw, v);
 }
 
+/* Set futex @f to @v and wake up all waiters */
+static inline void futex_add_and_wake(futex_t *f, uint32_t v)
+{
+	atomic_add(v, &f->raw);
+	BUG_ON(sys_futex(&f->raw, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+}
+
+
 #define futex_init(f)	futex_set(f, 0)
 
 /* Wait on futex @__f value @__v become in condition @__c */
@@ -82,6 +90,13 @@ static inline void futex_dec_and_wake(futex_t *f)
 	BUG_ON(sys_futex(&f->raw, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
 }
 
+/* Increment futex @f value and wake up all waiters */
+static inline void futex_inc_and_wake(futex_t *f)
+{
+	atomic_inc(&f->raw);
+	BUG_ON(sys_futex(&f->raw, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+}
+
 /* Plain increment futex @f value */
 static inline void futex_inc(futex_t *f) { atomic_inc(&f->raw); }
 
@@ -96,6 +111,9 @@ static inline void futex_wait_until(futex_t *f, uint32_t v)
 static inline void futex_wait_while_gt(futex_t *f, uint32_t v)
 { futex_wait_if_cond(f, v, <=); }
 
+/* Wait while futex @f value is less than @v */
+static inline void futex_wait_while_lt(futex_t *f, uint32_t v)
+{ futex_wait_if_cond(f, v, >=); }
 /* Wait while futex @f value is @v */
 static inline uint32_t futex_wait_while(futex_t *f, uint32_t v)
 {
-- 
1.8.5.3



More information about the CRIU mailing list