[CRIU] [PATCH 6/8] zdtm/lib: add futex_cmpxchg and futex_cmpxchg_and_wake
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Thu Feb 15 13:06:53 MSK 2018
From: ptikhomirov <ptikhomirov at virtuozzo.com>
These are usefull as we want to indicate predump status in the same
futex where we indicate test running/finished state, we don't want
predump state replace finished state so we should check and update the
state in one atomic transaction.
https://jira.sw.ru/browse/PSBM-67502
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
test/zdtm/lib/lock.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/test/zdtm/lib/lock.h b/test/zdtm/lib/lock.h
index db9e96d0e..5acaa876c 100644
--- a/test/zdtm/lib/lock.h
+++ b/test/zdtm/lib/lock.h
@@ -41,6 +41,11 @@ static inline void futex_set(futex_t *f, uint32_t v)
atomic_set(&f->raw, v);
}
+static inline int futex_cmpxchg(futex_t *f, uint32_t old, uint32_t new)
+{
+ return atomic_cmpxchg(&f->raw, old, new);
+}
+
/* Set futex @f to @v and wake up all waiters */
static inline void futex_add_and_wake(futex_t *f, uint32_t v)
{
@@ -77,6 +82,16 @@ static inline void futex_set_and_wake(futex_t *f, uint32_t v)
BUG_ON(sys_futex(&f->raw, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
}
+static inline int futex_cmpxchg_and_wake(futex_t *f, uint32_t old, uint32_t new)
+{
+ uint32_t ret;
+
+ ret = atomic_cmpxchg(&f->raw, old, new);
+ if (ret == old)
+ BUG_ON(sys_futex(&f->raw, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+ return ret;
+}
+
/* Mark futex @f as wait abort needed and wake up all waiters */
static inline void futex_abort_and_wake(futex_t *f)
{
--
2.14.3
More information about the CRIU
mailing list