Commit 71cc2733 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarAndrey Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent dc848fae
......@@ -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.
......
......@@ -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_ */
......@@ -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 */
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment