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/socket.c | |
| 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/socket.c')
| -rw-r--r-- | src/core/socket.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index 6c43e43d..d9ac12b6 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -16,12 +16,6 @@ // Socket implementation. -static nni_list sock_list; -static nni_id_map sock_ids; -static nni_mtx sock_lk; -static nni_id_map ctx_ids; -static bool inited; - struct nni_ctx { nni_list_node c_node; nni_sock *c_sock; @@ -107,6 +101,11 @@ struct nni_socket { #endif }; +static nni_list sock_list = NNI_LIST_INITIALIZER(sock_list, nni_sock, s_node); +static nni_mtx sock_lk = NNI_MTX_INITIALIZER; +static nni_id_map sock_ids; +static nni_id_map ctx_ids; + static void nni_ctx_destroy(nni_ctx *); #define SOCK(s) ((nni_sock *) (s)) @@ -611,12 +610,8 @@ nni_sock_create(nni_sock **sp, const nni_proto *proto) void nni_sock_sys_init(void) { - NNI_LIST_INIT(&sock_list, nni_sock, s_node); - nni_mtx_init(&sock_lk); - nni_id_map_init(&sock_ids, 1, 0x7fffffff, false); nni_id_map_init(&ctx_ids, 1, 0x7fffffff, false); - inited = true; } void @@ -624,8 +619,6 @@ nni_sock_sys_fini(void) { nni_id_map_fini(&sock_ids); nni_id_map_fini(&ctx_ids); - nni_mtx_fini(&sock_lk); - inited = false; } int @@ -822,9 +815,6 @@ nni_sock_closeall(void) { nni_sock *s; - if (!inited) { - return; - } for (;;) { nni_mtx_lock(&sock_lk); if ((s = nni_list_first(&sock_list)) == NULL) { |
