From c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 5 Dec 2021 22:11:24 -0500 Subject: Use static initialization for lists and mutexes. This eliminates some run-time initialization, moving it to compile time. Additional follow up work will expand on this to simplify initialization and reduce the need for certain locks. --- src/core/list.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/core/list.h') diff --git a/src/core/list.h b/src/core/list.h index 204057a2..d3c703bb 100644 --- a/src/core/list.h +++ b/src/core/list.h @@ -29,6 +29,16 @@ extern void nni_list_init_offset(nni_list *list, size_t offset); #define NNI_LIST_INIT(list, type, field) \ nni_list_init_offset(list, offsetof(type, field)) +// NNI_LIST_INITIALIZER is used to initialize structures at declaration time. +// The list argument is the structure being initialized and the type and +// offset determine where the node lives within each item. +#define NNI_LIST_INITIALIZER(list, type, field) \ + { \ + .ll_head.ln_next = &(list).ll_head, \ + .ll_head.ln_prev = &(list).ll_head, \ + .ll_offset = offsetof(type, field) \ + } + #define NNI_LIST_NODE_INIT(node) \ do { \ (node)->ln_prev = (node)->ln_next = 0; \ -- cgit v1.2.3-70-g09d2