2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +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)
goto err;
cr_mutex_init(&task_args->rst_lock);
mutex_init(&task_args->rst_lock);
/*
* 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)
}
}
/*
* 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_ */

View File

@@ -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 */

View File

@@ -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,