[CRIU] [PATCH 2/2] lock: Add own type and helpers for mutexes

Cyrill Gorcunov gorcunov at openvz.org
Mon Mar 26 11:38:33 EDT 2012


To be consistent. Mutexes are futex based but have
own semantics so better to be able to distinguish
the types.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-restore.c       |    2 +-
 include/lock.h     |   33 ++++++++++++---------------------
 include/restorer.h |    4 ++--
 restorer.c         |    4 ++--
 4 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 1787573..320405c 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1653,7 +1653,7 @@ static int sigreturn_restore(pid_t pid)
 	if (ret < 0)
 		goto err;
 
-	cr_mutex_init(&task_args->rst_lock);
+	mutex_init(&task_args->rst_lock);
 
 	/*
 	 * Now prepare run-time data for threads restore.
diff --git a/include/lock.h b/include/lock.h
index 1a5eb6b..6f77bfd 100644
--- a/include/lock.h
+++ b/include/lock.h
@@ -82,41 +82,32 @@ static inline void futex_wait_while(futex_t *f, u32 v)
 	}
 }
 
-/*
- * Init @mutex value
- */
-static void always_inline cr_mutex_init(u32 *mutex)
+typedef struct {
+	u32	raw;
+} mutex_t;
+
+static void inline mutex_init(mutex_t *m)
 {
 	u32 c = 0;
-	atomic_set(mutex, c);
+	atomic_set(&m->raw, c);
 }
 
-/*
- * Lock @mutex
- */
-static void always_inline cr_mutex_lock(u32 *mutex)
+static void inline mutex_lock(mutex_t *m)
 {
 	u32 c;
 	int ret;
 
-	while ((c = atomic_inc(mutex))) {
-		ret = sys_futex(mutex, FUTEX_WAIT, c + 1, NULL, NULL, 0);
+	while ((c = atomic_inc(&m->raw))) {
+		ret = sys_futex(&m->raw, FUTEX_WAIT, c + 1, NULL, NULL, 0);
 		BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
 	}
 }
 
-/*
- * Unlock @mutex
- */
-static void always_inline cr_mutex_unlock(u32 *mutex)
+static void inline mutex_unlock(mutex_t *m)
 {
 	u32 c = 0;
-	int ret;
-
-	atomic_set(mutex, c);
-
-	ret = sys_futex(mutex, FUTEX_WAKE, 1, NULL, NULL, 0);
-	BUG_ON(ret < 0);
+	atomic_set(&m->raw, c);
+	BUG_ON(sys_futex(&m->raw, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
 }
 
 #endif /* CR_LOCK_H_ */
diff --git a/include/restorer.h b/include/restorer.h
index 639e9f9..14c7dd0 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -57,7 +57,7 @@ struct thread_restore_args {
 
 	int				pid;
 	int				fd_core;
-	u32				*rst_lock;
+	mutex_t				*rst_lock;
 } __aligned(sizeof(long));
 
 struct task_restore_core_args {
@@ -70,7 +70,7 @@ struct task_restore_core_args {
 	int				fd_pages;		/* opened pages dump file */
 	int				logfd;
 	bool				restore_threads;	/* if to restore threads */
-	u32				rst_lock;
+	mutex_t				rst_lock;
 
 	/* threads restoration */
 	int				nr_threads;		/* number of threads */
diff --git a/restorer.c b/restorer.c
index 889cd2f..6cc9b60 100644
--- a/restorer.c
+++ b/restorer.c
@@ -200,7 +200,7 @@ long restore_thread(struct thread_restore_args *args)
 		goto core_restore_end;
 	}
 
-	cr_mutex_unlock(args->rst_lock);
+	mutex_unlock(args->rst_lock);
 
 	/*
 	 * FIXME -- threads do not share creds, but it looks like
@@ -577,7 +577,7 @@ long restore_task(struct task_restore_core_args *args)
 			if (thread_args[i].pid == args->pid)
 				continue;
 
-			cr_mutex_lock(&args->rst_lock);
+			mutex_lock(&args->rst_lock);
 
 			new_sp =
 				RESTORE_ALIGN_STACK((long)thread_args[i].mem_zone.stack,
-- 
1.7.7.6



More information about the CRIU mailing list