diff --git a/cr-restore.c b/cr-restore.c index 17875736f..320405c74 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 1a5eb6b5e..6f77bfd8e 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 639e9f958..14c7dd047 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 889cd2f8e..6cc9b6026 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,