From 713b80f440cb414cd0b856bde0ea1b31f939777f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 9 Nov 2024 23:45:21 -0800 Subject: refactor initialization/finalization Applications must now call nng_init(), but they can supply a set of parameters optionally. The code is now safe for multiple libraries to do this concurrently, meaning nng_fini no longer can race against another instance starting up. The nni_init checks on all public APIs are removed now. --- src/core/aio.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'src/core/aio.c') diff --git a/src/core/aio.c b/src/core/aio.c index 1c7e41d1..e1e9c42f 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -823,24 +823,13 @@ nni_aio_sys_fini(void) } int -nni_aio_sys_init(void) +nni_aio_sys_init(nng_init_params *params) { - int num_thr; - int max_thr; + int16_t num_thr; + int16_t max_thr; -#ifndef NNG_MAX_EXPIRE_THREADS -#define NNG_MAX_EXPIRE_THREADS 8 -#endif - -#ifndef NNG_NUM_EXPIRE_THREADS -#define NNG_NUM_EXPIRE_THREADS (nni_plat_ncpu()) -#endif - - max_thr = (int) nni_init_get_param( - NNG_INIT_MAX_EXPIRE_THREADS, NNG_MAX_EXPIRE_THREADS); - - num_thr = (int) nni_init_get_param( - NNG_INIT_NUM_EXPIRE_THREADS, NNG_NUM_EXPIRE_THREADS); + max_thr = params->max_expire_threads; + num_thr = params->num_expire_threads; if ((max_thr > 0) && (num_thr > max_thr)) { num_thr = max_thr; @@ -848,7 +837,7 @@ nni_aio_sys_init(void) if (num_thr < 1) { num_thr = 1; } - nni_init_set_effective(NNG_INIT_NUM_EXPIRE_THREADS, num_thr); + params->num_expire_threads = num_thr; nni_aio_expire_q_list = nni_zalloc(sizeof(nni_aio_expire_q *) * num_thr); nni_aio_expire_q_cnt = num_thr; -- cgit v1.2.3-70-g09d2