[1/2,v2] criu: lock -- Add completions

Submitted by Kirill Gorkunov on April 20, 2016, 6:47 p.m.

Details

Message ID 20160420184748.GC8387@uranus.sw.swsoft.com
State Rejected
Series "criu: restore -- Wait for userns completion"
Headers show

Patch hide | download patch | download mbox

diff --git a/criu/include/lock.h b/criu/include/lock.h
index 1678d10..4f6b0f7 100644
--- a/criu/include/lock.h
+++ b/criu/include/lock.h
@@ -154,4 +154,27 @@  static inline void mutex_unlock(mutex_t *m)
 	BUG_ON(sys_futex((u32 *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
 }
 
+typedef futex_t completion_t;
+
+static inline void init_completion(completion_t *c)
+{
+	futex_init(c);
+}
+
+static inline void complete(completion_t *c)
+{
+	futex_set_and_wake(c, 1);
+}
+
+static inline void abort_completion(completion_t *c)
+{
+	futex_abort_and_wake(c);
+}
+
+static inline int wait_for_completion(completion_t *c)
+{
+	futex_wait_until(c, 1);
+	return (atomic_read(&c->raw) & FUTEX_ABORT_FLAG) ? 1 : 0;
+}
+
 #endif /* __CR_LOCK_H__ */