[CRIU] [PATCH 3/4] lock: Get rid of logging dep

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


We gonna share this file between subprojects
so lets minimize deps on headers, only syscalls
are left here for non libc compiling.

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

diff --git a/criu/include/lock.h b/criu/include/lock.h
index fe087f182fb8..0a9921186d52 100644
--- a/criu/include/lock.h
+++ b/criu/include/lock.h
@@ -8,7 +8,11 @@
 #include <errno.h>
 
 #include "atomic.h"
-#include "bug.h"
+
+#define LOCK_BUG_ON(condition)							\
+	if ((condition))							\
+		*(volatile unsigned long *)NULL = 0xdead0000 + __LINE__
+#define LOCK_BUG()	LOCK_BUG_ON(1)
 
 #ifdef CR_NOGLIBC
 # include "uapi/std/syscall.h"
@@ -59,16 +63,12 @@ static inline void futex_set(futex_t *f, uint32_t v)
 				break;				\
 			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"); \
+			if (ret == -ETIMEDOUT)			\
 				continue;			\
-			}					\
 			if (ret == -EINTR || ret == -EWOULDBLOCK) \
 				continue;			\
-			if (ret < 0) {				\
-				pr_err("futex() returned an unexpected error: %d\n", ret); \
-				BUG();				\
-			}					\
+			if (ret < 0)				\
+				LOCK_BUG();			\
 		}						\
 	} while (0)
 
@@ -76,7 +76,7 @@ static inline void futex_set(futex_t *f, uint32_t v)
 static inline void futex_set_and_wake(futex_t *f, uint32_t v)
 {
 	atomic_set(&f->raw, (int)v);
-	BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+	LOCK_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 */
@@ -90,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((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+	LOCK_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((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+	LOCK_BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
 }
 
 /* Plain increment futex @f value */
@@ -123,7 +123,7 @@ static inline void futex_wait_while(futex_t *f, uint32_t v)
 {
 	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);
+		LOCK_BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
 	}
 }
 
@@ -144,7 +144,7 @@ static inline void mutex_lock(mutex_t *m)
 
 	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);
+		LOCK_BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
 	}
 }
 
@@ -152,7 +152,7 @@ static inline void mutex_unlock(mutex_t *m)
 {
 	uint32_t c = 0;
 	atomic_set(&m->raw, (int)c);
-	BUG_ON(sys_futex((uint32_t *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
+	LOCK_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