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/supplemental/http/http_server.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/supplemental/http/http_server.c')
| -rw-r--r-- | src/supplemental/http/http_server.c | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index 7f6f9abe..b7e7ac80 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -22,15 +22,6 @@ #include "http_api.h" -static int http_server_sys_init(void); -static void http_server_sys_fini(void); - -static nni_initializer http_server_initializer = { - .i_init = http_server_sys_init, - .i_fini = http_server_sys_fini, - .i_once = 0, -}; - struct nng_http_handler { nni_list_node node; char * uri; @@ -279,8 +270,9 @@ nni_http_handler_set_method(nni_http_handler *h, const char *method) return (0); } -static nni_list http_servers; -static nni_mtx http_servers_lk; +static nni_list http_servers = + NNI_LIST_INITIALIZER(http_servers, nni_http_server, node); +static nni_mtx http_servers_lk = NNI_MTX_INITIALIZER; static void http_sc_reap(void *arg) @@ -1001,8 +993,6 @@ nni_http_server_init(nni_http_server **serverp, const nni_url *url) int rv; nni_http_server *s; - nni_initialize(&http_server_initializer); - nni_mtx_lock(&http_servers_lk); NNI_LIST_FOREACH (&http_servers, s) { if ((!s->closed) && (atoi(url->u_port) == s->port) && @@ -1924,18 +1914,3 @@ nni_http_server_fini(nni_http_server *s) } nni_mtx_unlock(&http_servers_lk); } - -static int -http_server_sys_init(void) -{ - NNI_LIST_INIT(&http_servers, nni_http_server, node); - nni_mtx_init(&http_servers_lk); - return (0); -} - -static void -http_server_sys_fini(void) -{ - nni_reap_drain(); - nni_mtx_fini(&http_servers_lk); -} |
