diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-11 13:58:06 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-11 13:58:06 -0700 |
| commit | 674a3ed159c0a6ec9b62208837c388502ed80088 (patch) | |
| tree | 11a2764a8f205ffc230971949108daec80b59f0b /src/platform | |
| parent | 69e8b1517c6d84f30367c5c32e7426d81dc28265 (diff) | |
| download | nng-674a3ed159c0a6ec9b62208837c388502ed80088.tar.gz nng-674a3ed159c0a6ec9b62208837c388502ed80088.tar.bz2 nng-674a3ed159c0a6ec9b62208837c388502ed80088.zip | |
Windows fixes; especially idempotent init/fini.
This fixes one major problem, which was that if nni_fini() was called
once on Windows, it would not be further possible to call nni_init().
While here fixed a few compilation issues.
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/windows/win_thread.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index f78bfd9a..c01ec782 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -141,20 +141,21 @@ nni_plat_thr_fini(nni_plat_thr *thr) } } +static LONG plat_inited = 0; + int nni_plat_init(int (*helper)(void)) { - static LONG inited = 0; int rv; static SRWLOCK lock = SRWLOCK_INIT; - if (inited) { + if (plat_inited) { return (0); // fast path } AcquireSRWLockExclusive(&lock); - if (!inited) { + if (!plat_inited) { if ((rv = nni_win_iocp_sysinit()) != 0) { goto out; } @@ -169,7 +170,7 @@ nni_plat_init(int (*helper)(void)) } helper(); - inited = 1; + plat_inited = 1; } out: @@ -186,6 +187,7 @@ nni_plat_fini(void) nni_win_tcp_sysfini(); nni_win_iocp_sysfini(); WSACleanup(); + plat_inited = 0; } #else |
