diff options
Diffstat (limited to 'src/platform/windows')
| -rw-r--r-- | src/platform/windows/win_impl.h | 4 | ||||
| -rw-r--r-- | src/platform/windows/win_io.c | 29 | ||||
| -rw-r--r-- | src/platform/windows/win_resolv.c | 16 | ||||
| -rw-r--r-- | src/platform/windows/win_thread.c | 39 |
4 files changed, 31 insertions, 57 deletions
diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h index 1354709b..d94e1547 100644 --- a/src/platform/windows/win_impl.h +++ b/src/platform/windows/win_impl.h @@ -107,7 +107,7 @@ extern int nni_win_error(int); extern int nni_win_tcp_conn_init(nni_tcp_conn **, SOCKET); -extern int nni_win_io_sysinit(void); +extern int nni_win_io_sysinit(nng_init_params *params); extern void nni_win_io_sysfini(void); extern int nni_win_ipc_sysinit(void); @@ -119,7 +119,7 @@ extern void nni_win_tcp_sysfini(void); extern int nni_win_udp_sysinit(void); extern void nni_win_udp_sysfini(void); -extern int nni_win_resolv_sysinit(void); +extern int nni_win_resolv_sysinit(nng_init_params *); extern void nni_win_resolv_sysfini(void); extern void nni_win_io_init(nni_win_io *, nni_win_io_cb, void *); diff --git a/src/platform/windows/win_io.c b/src/platform/windows/win_io.c index 47dd7408..815f9bf3 100644 --- a/src/platform/windows/win_io.c +++ b/src/platform/windows/win_io.c @@ -71,25 +71,16 @@ nni_win_io_init(nni_win_io *io, nni_win_io_cb cb, void *ptr) } int -nni_win_io_sysinit(void) +nni_win_io_sysinit(nng_init_params *params) { - HANDLE h; - int i; - int rv; - int num_thr; - int max_thr; - -#ifndef NNG_MAX_POLLER_THREADS -#define NNG_MAX_POLLER_THREADS 8 -#endif -#ifndef NNG_NUM_POLLER_THREADS -#define NNG_NUM_POLLER_THREADS (nni_plat_ncpu()) -#endif - max_thr = (int) nni_init_get_param( - NNG_INIT_MAX_POLLER_THREADS, NNG_MAX_POLLER_THREADS); - - num_thr = (int) nni_init_get_param( - NNG_INIT_NUM_POLLER_THREADS, NNG_NUM_POLLER_THREADS); + HANDLE h; + int i; + int rv; + int16_t num_thr; + int16_t max_thr; + + max_thr = params->max_poller_threads; + num_thr = params->num_poller_threads; if ((max_thr > 0) && (num_thr > max_thr)) { num_thr = max_thr; @@ -97,7 +88,7 @@ nni_win_io_sysinit(void) if (num_thr < 1) { num_thr = 1; } - nni_init_set_effective(NNG_INIT_NUM_POLLER_THREADS, num_thr); + params->num_poller_threads = num_thr; if ((win_io_thrs = NNI_ALLOC_STRUCTS(win_io_thrs, num_thr)) == NULL) { return (NNG_ENOMEM); } diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c index 4f353e08..1b1ae7b9 100644 --- a/src/platform/windows/win_resolv.c +++ b/src/platform/windows/win_resolv.c @@ -27,7 +27,7 @@ static nni_cv resolv_cv = NNI_CV_INITIALIZER(&resolv_mtx); static bool resolv_fini = false; static nni_list resolv_aios; static nni_thr *resolv_thrs; -static int resolv_num_thr; +static int16_t resolv_num_thr; typedef struct resolv_item resolv_item; struct resolv_item { @@ -432,28 +432,24 @@ nni_parse_ip_port(const char *addr, nni_sockaddr *sa) } int -nni_win_resolv_sysinit(void) +nni_win_resolv_sysinit(nng_init_params *params) { nni_aio_list_init(&resolv_aios); resolv_fini = false; -#ifndef NNG_RESOLV_CONCURRENCY -#define NNG_RESOLV_CONCURRENCY 4 -#endif - - resolv_num_thr = (int) nni_init_get_param( - NNG_INIT_NUM_RESOLVER_THREADS, NNG_RESOLV_CONCURRENCY); + resolv_num_thr = params->num_resolver_threads; if (resolv_num_thr < 1) { resolv_num_thr = 1; } + params->num_resolver_threads = resolv_num_thr; + // no limit on the maximum for now - nni_init_set_effective(NNG_INIT_NUM_RESOLVER_THREADS, resolv_num_thr); resolv_thrs = NNI_ALLOC_STRUCTS(resolv_thrs, resolv_num_thr); if (resolv_thrs == NULL) { return (NNG_ENOMEM); } - for (int i = 0; i < resolv_num_thr; i++) { + for (int16_t i = 0; i < resolv_num_thr; i++) { int rv = nni_thr_init(&resolv_thrs[i], resolv_worker, NULL); if (rv != 0) { nni_win_resolv_sysfini(); diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index 67ff60b2..a6416cd8 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -416,8 +416,6 @@ nni_plat_thr_set_name(nni_plat_thr *thr, const char *name) } } -static LONG plat_inited = 0; - int nni_plat_ncpu(void) { @@ -428,36 +426,26 @@ nni_plat_ncpu(void) } int -nni_plat_init(int (*helper)(void)) +nni_plat_init(nng_init_params *params) { int rv = 0; static SRWLOCK lock = SRWLOCK_INIT; - if (plat_inited) { - return (0); // fast path - } - AcquireSRWLockExclusive(&lock); - if (!plat_inited) { - // Let's look up the function to set thread descriptions. - hKernel32 = LoadLibrary(TEXT("kernel32.dll")); - if (hKernel32 != NULL) { - set_thread_desc = - (pfnSetThreadDescription) GetProcAddress( - hKernel32, "SetThreadDescription"); - } - - if (((rv = nni_win_io_sysinit()) != 0) || - ((rv = nni_win_ipc_sysinit()) != 0) || - ((rv = nni_win_tcp_sysinit()) != 0) || - ((rv = nni_win_udp_sysinit()) != 0) || - ((rv = nni_win_resolv_sysinit()) != 0)) { - goto out; - } + // Let's look up the function to set thread descriptions. + hKernel32 = LoadLibrary(TEXT("kernel32.dll")); + if (hKernel32 != NULL) { + set_thread_desc = (pfnSetThreadDescription) GetProcAddress( + hKernel32, "SetThreadDescription"); + } - helper(); - plat_inited = 1; + if (((rv = nni_win_io_sysinit(params)) != 0) || + ((rv = nni_win_ipc_sysinit()) != 0) || + ((rv = nni_win_tcp_sysinit()) != 0) || + ((rv = nni_win_udp_sysinit()) != 0) || + ((rv = nni_win_resolv_sysinit(params)) != 0)) { + goto out; } out: @@ -478,7 +466,6 @@ nni_plat_fini(void) if (hKernel32 != NULL) { FreeLibrary(hKernel32); } - plat_inited = 0; } #endif |
