aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_thread.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-09 23:45:21 -0800
committerGarrett D'Amore <garrett@damore.org>2024-11-11 11:03:12 -0800
commit713b80f440cb414cd0b856bde0ea1b31f939777f (patch)
tree1186c42418559c85719023bde3e919aa2df7fcef /src/platform/windows/win_thread.c
parentcbe9a27ef7485977fbc7c713376b096b6723da3d (diff)
downloadnng-713b80f440cb414cd0b856bde0ea1b31f939777f.tar.gz
nng-713b80f440cb414cd0b856bde0ea1b31f939777f.tar.bz2
nng-713b80f440cb414cd0b856bde0ea1b31f939777f.zip
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.
Diffstat (limited to 'src/platform/windows/win_thread.c')
-rw-r--r--src/platform/windows/win_thread.c39
1 files changed, 13 insertions, 26 deletions
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