[CRIU] [PATCH 1/4] criu: lock -- Use systemwide uintX types

Cyrill Gorcunov gorcunov at openvz.org
Fri Oct 21 04:51:22 PDT 2016


For portability sake, we gonna share this header.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/include/lock.h | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/criu/include/lock.h b/criu/include/lock.h
index 641fa1dc2af2..fe087f182fb8 100644
--- a/criu/include/lock.h
+++ b/criu/include/lock.h
@@ -1,6 +1,7 @@
 #ifndef __CR_LOCK_H__
 #define __CR_LOCK_H__
 
+#include <stdint.h>
 #include <linux/futex.h>
 #include <sys/time.h>
 #include <limits.h>
@@ -31,13 +32,13 @@ typedef struct {
 #define FUTEX_ABORT_RAW		(-1U)
 
 /* Get current futex @f value */
-static inline u32 futex_get(futex_t *f)
+static inline uint32_t futex_get(futex_t *f)
 {
 	return atomic_read(&f->raw);
 }
 
 /* Set futex @f value to @v */
-static inline void futex_set(futex_t *f, u32 v)
+static inline void futex_set(futex_t *f, uint32_t v)
 {
 	atomic_set(&f->raw, (int)v);
 }
@@ -48,7 +49,7 @@ static inline void futex_set(futex_t *f, u32 v)
 #define futex_wait_if_cond(__f, __v, __cond)			\
 	do {							\
 		int ret;					\
-		u32 tmp;					\
+		uint32_t tmp;					\
 								\
 		while (1) {					\
 			struct timespec to = {.tv_sec = 120};	\
@@ -56,7 +57,7 @@ static inline void futex_set(futex_t *f, u32 v)
 			if ((tmp & FUTEX_ABORT_FLAG) ||		\
 			    (tmp __cond (__v)))			\
 				break;				\
-			ret = sys_futex((u32 *)&(__f)->raw.counter, FUTEX_WAIT,\
+			ret = sys_futex((uint32_t *)&(__f)->raw.counter, FUTEX_WAIT,\
 					tmp, &to, NULL, 0);	\
 			if (ret == -ETIMEDOUT) {		\
 				pr_warn("blocked for more than 120 seconds\n"); \
@@ -72,10 +73,10 @@ static inline void futex_set(futex_t *f, u32 v)
 	} while (0)
 
 /* Set futex @f to @v and wake up all waiters */
-static inline void futex_set_and_wake(futex_t *f, u32 v)
+static inline void futex_set_and_wake(futex_t *f, uint32_t v)
 {
 	atomic_set(&f->raw, (int)v);
-	BUG_ON(sys_futex((u32 *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+	BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
 }
 
 /* Mark futex @f as wait abort needed and wake up all waiters */
@@ -89,14 +90,14 @@ static inline void futex_abort_and_wake(futex_t *f)
 static inline void futex_dec_and_wake(futex_t *f)
 {
 	atomic_dec(&f->raw);
-	BUG_ON(sys_futex((u32 *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+	BUG_ON(sys_futex((uint32_t *)&f->raw.counter, 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((u32 *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+	BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
 }
 
 /* Plain increment futex @f value */
@@ -118,10 +119,10 @@ static inline void futex_dec(futex_t *f) { atomic_dec(&f->raw); }
 #define futex_wait_while_eq(f, v) futex_wait_if_cond(f, v, !=)
 
 /* Wait while futex @f value is @v */
-static inline void futex_wait_while(futex_t *f, u32 v)
+static inline void futex_wait_while(futex_t *f, uint32_t v)
 {
-	while ((u32)atomic_read(&f->raw) == v) {
-		int ret = sys_futex((u32 *)&f->raw.counter, FUTEX_WAIT, v, NULL, NULL, 0);
+	while ((uint32_t)atomic_read(&f->raw) == v) {
+		int ret = sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAIT, v, NULL, NULL, 0);
 		BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
 	}
 }
@@ -132,26 +133,26 @@ typedef struct {
 
 static inline void mutex_init(mutex_t *m)
 {
-	u32 c = 0;
+	uint32_t c = 0;
 	atomic_set(&m->raw, (int)c);
 }
 
 static inline void mutex_lock(mutex_t *m)
 {
-	u32 c;
+	uint32_t c;
 	int ret;
 
-	while ((c = (u32)atomic_inc_return(&m->raw)) != 1) {
-		ret = sys_futex((u32 *)&m->raw.counter, FUTEX_WAIT, c, NULL, NULL, 0);
+	while ((c = (uint32_t)atomic_inc_return(&m->raw)) != 1) {
+		ret = sys_futex((uint32_t *)&m->raw.counter, FUTEX_WAIT, c, NULL, NULL, 0);
 		BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
 	}
 }
 
 static inline void mutex_unlock(mutex_t *m)
 {
-	u32 c = 0;
+	uint32_t c = 0;
 	atomic_set(&m->raw, (int)c);
-	BUG_ON(sys_futex((u32 *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
+	BUG_ON(sys_futex((uint32_t *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
 }
 
 #endif /* __CR_LOCK_H__ */
-- 
2.7.4



More information about the CRIU mailing list