diff options
| author | Garrett D'Amore <garrett@damore.org> | 2021-12-05 22:11:24 -0500 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2021-12-05 23:04:45 -0500 |
| commit | c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04 (patch) | |
| tree | 3a135bbee8750cc1b1869cfca6a2e6f24bf8e59c /src/core/list.h | |
| parent | eee06d1e8365ea1b1aa9363a3c6445745b002324 (diff) | |
| download | nng-c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04.tar.gz nng-c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04.tar.bz2 nng-c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04.zip | |
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.
Diffstat (limited to 'src/core/list.h')
| -rw-r--r-- | src/core/list.h | 10 |
1 files changed, 10 insertions, 0 deletions
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; \ |
