From: Andre Noll Date: Thu, 20 May 2021 18:38:34 +0000 (+0200) Subject: list.h: Convert INIT_LIST_HEAD macro to inline function. X-Git-Tag: v0.7.0~18^2 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=442a3320ff155d09b990c0ee2abace399cbcd6dd;hp=c0e4799bafc72ffdb7e8912317b8f74acbbc2736;ds=sidebyside list.h: Convert INIT_LIST_HEAD macro to inline function. Inline functions are easier to read and write, and we get type safety. --- diff --git a/afs.c b/afs.c index c4de2e8f..a219c2dd 100644 --- a/afs.c +++ b/afs.c @@ -981,7 +981,7 @@ __noreturn void afs_init(int socket_fd) int i, ret; register_signal_task(&s); - INIT_LIST_HEAD(&afs_client_list); + init_list_head(&afs_client_list); for (i = 0; i < NUM_AFS_TABLES; i++) afs_tables[i].init(&afs_tables[i]); ret = open_afs_tables(); diff --git a/buffer_tree.c b/buffer_tree.c index 8a317513..f0d2002d 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -270,8 +270,8 @@ struct btr_node *btr_new_node(struct btr_node_description *bnd) btrn->context = bnd->context; btrn->start.tv_sec = 0; btrn->start.tv_usec = 0; - INIT_LIST_HEAD(&btrn->children); - INIT_LIST_HEAD(&btrn->input_queue); + init_list_head(&btrn->children); + init_list_head(&btrn->input_queue); if (!bnd->child) { if (bnd->parent) { list_add_tail(&btrn->node, &bnd->parent->children); diff --git a/chunk_queue.c b/chunk_queue.c index 08f57e9d..cf74cc33 100644 --- a/chunk_queue.c +++ b/chunk_queue.c @@ -131,7 +131,7 @@ int cq_get(struct queued_chunk *qc, const char **buf, size_t *num_bytes) struct chunk_queue *cq_new(size_t max_pending) { struct chunk_queue *cq = para_malloc(sizeof(*cq)); - INIT_LIST_HEAD(&cq->q); + init_list_head(&cq->q); cq->max_pending = max_pending; cq->num_pending = 0; return cq; diff --git a/close_on_fork.c b/close_on_fork.c index 28c5eabb..7b464d09 100644 --- a/close_on_fork.c +++ b/close_on_fork.c @@ -34,7 +34,7 @@ void add_close_on_fork_list(int fd) struct close_on_fork *cof = para_malloc(sizeof(struct close_on_fork)); if (!initialized) { - INIT_LIST_HEAD(&close_on_fork_list); + init_list_head(&close_on_fork_list); initialized = 1; } cof->fd = fd; diff --git a/list.h b/list.h index ddcb69da..78c302fa 100644 --- a/list.h +++ b/list.h @@ -25,9 +25,11 @@ struct list_head { #define INITIALIZED_LIST_HEAD(name) struct list_head name = {&(name), &(name)} /** This must be called before using any other list functions. */ -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) +static inline void init_list_head(struct list_head *head) +{ + head->next = head; + head->prev = head; +} /** * Insert a new entry after the specified head. diff --git a/mood.c b/mood.c index a63d4d2a..d76cbaf3 100644 --- a/mood.c +++ b/mood.c @@ -263,9 +263,9 @@ static struct mood *alloc_new_mood(const char *name) struct mood *m = para_calloc(sizeof(struct mood)); if (name) m->name = para_strdup(name); - INIT_LIST_HEAD(&m->accept_list); - INIT_LIST_HEAD(&m->deny_list); - INIT_LIST_HEAD(&m->score_list); + init_list_head(&m->accept_list); + init_list_head(&m->deny_list); + init_list_head(&m->score_list); return m; } diff --git a/net.c b/net.c index 91200fc0..e1951e5e 100644 --- a/net.c +++ b/net.c @@ -288,7 +288,7 @@ struct flowopts *flowopt_new(void) { struct flowopts *new = para_malloc(sizeof(*new)); - INIT_LIST_HEAD(&new->sockopts); + init_list_head(&new->sockopts); return new; } diff --git a/sched.c b/sched.c index a2903940..aac8efed 100644 --- a/sched.c +++ b/sched.c @@ -244,7 +244,7 @@ struct task *task_register(struct task_info *info, struct sched *s) assert(info->post_select); if (!s->task_list.next) - INIT_LIST_HEAD(&s->task_list); + init_list_head(&s->task_list); t->info = *info; t->name = para_strdup(info->name); diff --git a/send_common.c b/send_common.c index ea494d9a..9debdfca 100644 --- a/send_common.c +++ b/send_common.c @@ -136,9 +136,9 @@ void init_sender_status(struct sender_status *ss, } ss->default_port = default_port; - INIT_LIST_HEAD(&ss->client_list); + init_list_head(&ss->client_list); /* Initialize an access control list */ - INIT_LIST_HEAD(&ss->acl); + init_list_head(&ss->acl); for (i = 0; i < lls_opt_given(acl_opt_result); i++) { const char *arg = lls_string_val(i, acl_opt_result); char addr[16]; diff --git a/sync_filter.c b/sync_filter.c index 2ca2a657..13bbcf1b 100644 --- a/sync_filter.c +++ b/sync_filter.c @@ -103,7 +103,7 @@ static void sync_open(struct filter_node *fn) const struct lls_opt_result *r_b; ctx = fn->private_data = para_calloc(sizeof(*ctx)); - INIT_LIST_HEAD(&ctx->buddies); + init_list_head(&ctx->buddies); /* create socket to listen for incoming packets */ ret = makesock( diff --git a/udp_send.c b/udp_send.c index 04e2982f..be161a86 100644 --- a/udp_send.c +++ b/udp_send.c @@ -392,7 +392,7 @@ static void udp_init_target_list(void) struct sender_command_data scd; int i; - INIT_LIST_HEAD(&targets); + init_list_head(&targets); for (i = 0; i < OPT_GIVEN(UDP_TARGET); i++) { const char *arg = lls_string_val(i, OPT_RESULT(UDP_TARGET)); if (udp_resolve_target(arg, &scd) < 0) @@ -425,7 +425,7 @@ static char *udp_help(void) /* Initialize the list of udp targets. */ static void udp_send_init(void) { - INIT_LIST_HEAD(&targets); + init_list_head(&targets); sender_status = SENDER_off; udp_init_target_list(); if (!OPT_GIVEN(UDP_NO_AUTOSTART)) diff --git a/vss.c b/vss.c index 9857d92d..ad5f7ec0 100644 --- a/vss.c +++ b/vss.c @@ -1170,7 +1170,7 @@ void vss_init(int afs_socket, struct sched *s) vsst->afs_socket = afs_socket; ms2tv(announce_time, &vsst->announce_tv); PARA_INFO_LOG("announce timeval: %lums\n", tv2ms(&vsst->announce_tv)); - INIT_LIST_HEAD(&fec_client_list); + init_list_head(&fec_client_list); FOR_EACH_SENDER(i) { PARA_NOTICE_LOG("initializing %s sender\n", senders[i]->name); senders[i]->init();