2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-02 15:25:21 +00:00

lock: Add own type and helpers for mutexes

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@openvz.org>
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Cyrill Gorcunov
2012-03-26 19:38:00 +04:00
committed by Pavel Emelyanov
parent dc848fae7a
commit 71cc2733a7
4 changed files with 17 additions and 26 deletions

View File

@@ -1653,7 +1653,7 @@ static int sigreturn_restore(pid_t pid)
if (ret < 0) if (ret < 0)
goto err; goto err;
cr_mutex_init(&task_args->rst_lock); mutex_init(&task_args->rst_lock);
/* /*
* Now prepare run-time data for threads restore. * Now prepare run-time data for threads restore.

View File

@@ -82,41 +82,32 @@ static inline void futex_wait_while(futex_t *f, u32 v)
} }
} }
/* typedef struct {
* Init @mutex value u32 raw;
*/ } mutex_t;
static void always_inline cr_mutex_init(u32 *mutex)
static void inline mutex_init(mutex_t *m)
{ {
u32 c = 0; u32 c = 0;
atomic_set(mutex, c); atomic_set(&m->raw, c);
} }
/* static void inline mutex_lock(mutex_t *m)
* Lock @mutex
*/
static void always_inline cr_mutex_lock(u32 *mutex)
{ {
u32 c; u32 c;
int ret; int ret;
while ((c = atomic_inc(mutex))) { while ((c = atomic_inc(&m->raw))) {
ret = sys_futex(mutex, FUTEX_WAIT, c + 1, NULL, NULL, 0); ret = sys_futex(&m->raw, FUTEX_WAIT, c + 1, NULL, NULL, 0);
BUG_ON(ret < 0 && ret != -EWOULDBLOCK); BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
} }
} }
/* static void inline mutex_unlock(mutex_t *m)
* Unlock @mutex
*/
static void always_inline cr_mutex_unlock(u32 *mutex)
{ {
u32 c = 0; u32 c = 0;
int ret; atomic_set(&m->raw, c);
BUG_ON(sys_futex(&m->raw, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
atomic_set(mutex, c);
ret = sys_futex(mutex, FUTEX_WAKE, 1, NULL, NULL, 0);
BUG_ON(ret < 0);
} }
#endif /* CR_LOCK_H_ */ #endif /* CR_LOCK_H_ */

View File

@@ -57,7 +57,7 @@ struct thread_restore_args {
int pid; int pid;
int fd_core; int fd_core;
u32 *rst_lock; mutex_t *rst_lock;
} __aligned(sizeof(long)); } __aligned(sizeof(long));
struct task_restore_core_args { struct task_restore_core_args {
@@ -70,7 +70,7 @@ struct task_restore_core_args {
int fd_pages; /* opened pages dump file */ int fd_pages; /* opened pages dump file */
int logfd; int logfd;
bool restore_threads; /* if to restore threads */ bool restore_threads; /* if to restore threads */
u32 rst_lock; mutex_t rst_lock;
/* threads restoration */ /* threads restoration */
int nr_threads; /* number of threads */ int nr_threads; /* number of threads */

View File

@@ -200,7 +200,7 @@ long restore_thread(struct thread_restore_args *args)
goto core_restore_end; 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 * 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) if (thread_args[i].pid == args->pid)
continue; continue;
cr_mutex_lock(&args->rst_lock); mutex_lock(&args->rst_lock);
new_sp = new_sp =
RESTORE_ALIGN_STACK((long)thread_args[i].mem_zone.stack, RESTORE_ALIGN_STACK((long)thread_args[i].mem_zone.stack,