[CRIU] [PATCH 3/5] restore: Tune up _once stuff
Pavel Emelyanov
xemul at virtuozzo.com
Fri May 26 05:45:09 PDT 2017
Having ppreh_heads we can simplify the _once helper
by re-using the .next field.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/include/crtools.h | 15 ++++++++++-----
criu/pipes.c | 4 +---
criu/sk-unix.c | 4 +---
criu/tty.c | 5 +----
4 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/criu/include/crtools.h b/criu/include/crtools.h
index 02059cb..a78a577 100644
--- a/criu/include/crtools.h
+++ b/criu/include/crtools.h
@@ -30,11 +30,16 @@ extern int cr_lazy_pages(bool daemon);
extern int check_add_feature(char *arg);
extern void pr_check_features(const char *offset, const char *sep, int width);
-#define add_post_prepare_cb_once(phead) do { \
- static int __cb_called = 0; \
- if (!__cb_called) \
- add_post_prepare_cb(phead); \
- __cb_called = 1; \
+#define PPREP_HEAD_INACTIVE ((struct pprep_head *)-1)
+
+#define add_post_prepare_cb_once(phead) do { \
+ if ((phead)->next == PPREP_HEAD_INACTIVE)\
+ add_post_prepare_cb(phead); \
} while (0)
+#define MAKE_PPREP_HEAD(name) struct pprep_head name = { \
+ .next = PPREP_HEAD_INACTIVE, \
+ .actor = name##_cb, \
+ }
+
#endif /* __CR_CRTOOLS_H__ */
diff --git a/criu/pipes.c b/criu/pipes.c
index c20fc61..cb150f3 100644
--- a/criu/pipes.c
+++ b/criu/pipes.c
@@ -141,9 +141,7 @@ static int mark_pipe_master_cb(struct pprep_head *ph)
return 0;
}
-static struct pprep_head mark_pipe_master = {
- .actor = mark_pipe_master_cb,
-};
+static MAKE_PPREP_HEAD(mark_pipe_master);
static struct pipe_data_rst *pd_hash_pipes[PIPE_DATA_HASH_SIZE];
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index bf19024..8ba41d9 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -1376,9 +1376,7 @@ static void unlink_stale(struct unix_sk_info *ui)
}
static int resolve_unix_peers_cb(struct pprep_head *ph);
-static struct pprep_head resolve_unix_peers = {
- .actor = resolve_unix_peers_cb,
-};
+static MAKE_PPREP_HEAD(resolve_unix_peers);
static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
{
diff --git a/criu/tty.c b/criu/tty.c
index 624e3ff..5ad567c 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -1568,10 +1568,7 @@ static int prep_tty_restore_cb(struct pprep_head *ph)
return 0;
}
-static struct pprep_head prep_tty_restore = {
- .actor = prep_tty_restore_cb,,
-};
-
+static MAKE_PPREP_HEAD(prep_tty_restore);
static int collect_one_tty(void *obj, ProtobufCMessage *msg, struct cr_img *i)
{
--
2.1.4
More information about the CRIU
mailing list