diff options
| -rw-r--r-- | src/core/device.c | 1 | ||||
| -rw-r--r-- | src/core/event.c | 2 | ||||
| -rw-r--r-- | src/core/msgqueue.c | 1 | ||||
| -rw-r--r-- | src/core/objhash.c | 3 | ||||
| -rw-r--r-- | src/core/platform.h | 6 | ||||
| -rw-r--r-- | src/core/socket.c | 6 | ||||
| -rw-r--r-- | src/platform/posix/posix_config.h | 2 | ||||
| -rw-r--r-- | src/platform/posix/posix_pollq.h | 4 | ||||
| -rw-r--r-- | src/platform/windows/win_debug.c | 1 | ||||
| -rw-r--r-- | src/platform/windows/win_impl.h | 10 | ||||
| -rw-r--r-- | src/platform/windows/win_thread.c | 33 |
11 files changed, 23 insertions, 46 deletions
diff --git a/src/core/device.c b/src/core/device.c index 7b2b5b87..7d0454bd 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -56,7 +56,6 @@ static void nni_device_rev(void *p) { nni_device_pair *pair = p; - int rv; pair->err[1] = nni_device_loop(pair->socks[1], pair->socks[0]); nni_sock_shutdown(pair->socks[0]); diff --git a/src/core/event.c b/src/core/event.c index b0e02b16..df9618ca 100644 --- a/src/core/event.c +++ b/src/core/event.c @@ -15,8 +15,6 @@ int nni_ev_init(nni_event *event, int type, nni_sock *sock) { - int rv; - memset(event, 0, sizeof (*event)); event->e_type = type; event->e_sock = sock; diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c index 985563ad..a69af47c 100644 --- a/src/core/msgqueue.c +++ b/src/core/msgqueue.c @@ -510,7 +510,6 @@ nni_msgq_run_timeout(void *arg) nni_time exp; nni_aio *aio; nni_aio *naio; - int rv; now = nni_clock(); exp = NNI_TIME_NEVER; diff --git a/src/core/objhash.c b/src/core/objhash.c index 99ab7560..da4c6012 100644 --- a/src/core/objhash.c +++ b/src/core/objhash.c @@ -137,7 +137,6 @@ nni_objhash_find_node(nni_objhash *oh, uint32_t id) int nni_objhash_find(nni_objhash *oh, uint32_t id, void **valp) { - uint32_t index; nni_objhash_node *node; int rv; @@ -242,7 +241,6 @@ nni_objhash_resize(nni_objhash *oh, int grow) void nni_objhash_unref(nni_objhash *oh, uint32_t id) { - int rv; void *val; uint32_t index; nni_objhash_node *node; @@ -309,7 +307,6 @@ nni_objhash_unref(nni_objhash *oh, uint32_t id) void nni_objhash_unref_wait(nni_objhash *oh, uint32_t id) { - int rv; void *val; uint32_t index; nni_objhash_node *node; diff --git a/src/core/platform.h b/src/core/platform.h index 11a01abb..107b180e 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -76,9 +76,9 @@ extern void *nni_alloc(size_t); // Most implementations can just call free() here. extern void nni_free(void *, size_t); -typedef struct nni_plat_mtx nni_plat_mtx; -typedef struct nni_plat_cv nni_plat_cv; -typedef struct nni_plat_thr nni_plat_thr; +typedef struct nni_plat_mtx nni_plat_mtx; +typedef struct nni_plat_cv nni_plat_cv; +typedef struct nni_plat_thr nni_plat_thr; // // Threading & Synchronization Support diff --git a/src/core/socket.c b/src/core/socket.c index 66f5c63b..f7712aa3 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -472,7 +472,6 @@ nni_sock_shutdown(nni_sock *sock) nni_pipe *pipe; nni_ep *ep; nni_time linger; - int i; nni_mtx_lock(&sock->s_mx); if (sock->s_closing) { @@ -577,8 +576,6 @@ nni_sock_shutdown(nni_sock *sock) int nni_sock_ep_add(nni_sock *sock, nni_ep *ep) { - int rv; - nni_mtx_lock(&sock->s_mx); if (sock->s_closing) { nni_mtx_unlock(&sock->s_mx); @@ -613,9 +610,6 @@ nni_sock_ep_remove(nni_sock *sock, nni_ep *ep) void nni_sock_close(nni_sock *sock) { - int i; - nni_notify *notify; - // Shutdown everything if not already done. This operation // is idempotent. nni_sock_shutdown(sock); diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h index 1fe4d1a9..7e82a050 100644 --- a/src/platform/posix/posix_config.h +++ b/src/platform/posix/posix_config.h @@ -63,4 +63,4 @@ #define NNG_USE_POSIX_POLLQ_POLL 1 #define NNG_USE_POSIX_RESOLV_GAI 1 -#endif // PLATFORM_POSIX
\ No newline at end of file +#endif // PLATFORM_POSIX diff --git a/src/platform/posix/posix_pollq.h b/src/platform/posix/posix_pollq.h index a04d1ef2..224bf765 100644 --- a/src/platform/posix/posix_pollq.h +++ b/src/platform/posix/posix_pollq.h @@ -42,6 +42,6 @@ extern void nni_posix_pollq_cancel(nni_posix_pollq *, nni_posix_pollq_node *); extern int nni_posix_pollq_sysinit(void); extern void nni_posix_pollq_sysfini(void); -#endif // PLATFORM_POSIX +#endif // PLATFORM_POSIX -#endif // PLATFORM_POSIX_POLLQ_H +#endif // PLATFORM_POSIX_POLLQ_H diff --git a/src/platform/windows/win_debug.c b/src/platform/windows/win_debug.c index a4edef0d..43db0505 100644 --- a/src/platform/windows/win_debug.c +++ b/src/platform/windows/win_debug.c @@ -77,6 +77,7 @@ nni_plat_errno(int errnum) return (NNG_ESYSERR + errnum); } + // Windows has infinite numbers of error codes it seems. We only bother // with the ones that are relevant to us (we think). Note that there is // no overlap between errnos and GetLastError values. diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h index 85f73bf7..fd8f3f79 100644 --- a/src/platform/windows/win_impl.h +++ b/src/platform/windows/win_impl.h @@ -26,7 +26,7 @@ // These types are provided for here, to permit them to be directly inlined // elsewhere. -typedef struct nni_win_event nni_win_event; +typedef struct nni_win_event nni_win_event; // nni_win_event is used with io completion ports. This allows us to get // to a specific completion callback without requiring the poller (in the @@ -60,14 +60,14 @@ struct nni_plat_thr { }; struct nni_plat_mtx { - CRITICAL_SECTION cs; - DWORD owner; - int init; + SRWLOCK srl; + DWORD owner; + int init; }; struct nni_plat_cv { CONDITION_VARIABLE cv; - CRITICAL_SECTION * cs; + PSRWLOCK srl; }; extern int nni_win_error(int); diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index be94d638..f3103079 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -34,7 +34,7 @@ nni_free(void *b, size_t z) int nni_plat_mtx_init(nni_plat_mtx *mtx) { - InitializeCriticalSection(&mtx->cs); + InitializeSRWLock(&mtx->srl); mtx->init = 1; return (0); } @@ -43,24 +43,21 @@ nni_plat_mtx_init(nni_plat_mtx *mtx) void nni_plat_mtx_fini(nni_plat_mtx *mtx) { - if (mtx->init) { - DeleteCriticalSection(&mtx->cs); - mtx->init = 0; - } + mtx->init = 0; } void nni_plat_mtx_lock(nni_plat_mtx *mtx) { - EnterCriticalSection(&mtx->cs); + AcquireSRWLockExclusive(&mtx->srl); } void nni_plat_mtx_unlock(nni_plat_mtx *mtx) { - LeaveCriticalSection(&mtx->cs); + ReleaseSRWLockExclusive(&mtx->srl); } @@ -68,7 +65,7 @@ int nni_plat_cv_init(nni_plat_cv *cv, nni_plat_mtx *mtx) { InitializeConditionVariable(&cv->cv); - cv->cs = &mtx->cs; + cv->srl = &mtx->srl; return (0); } @@ -83,7 +80,7 @@ nni_plat_cv_wake(nni_plat_cv *cv) void nni_plat_cv_wait(nni_plat_cv *cv) { - (void) SleepConditionVariableCS(&cv->cv, cv->cs, INFINITE); + (void) SleepConditionVariableSRW(&cv->cv, cv->srl, INFINITE, 0); } @@ -102,7 +99,7 @@ nni_plat_cv_until(nni_plat_cv *cv, nni_time until) msec = (DWORD) (((until - now) + 999)/1000); } - ok = SleepConditionVariableCS(&cv->cv, cv->cs, msec); + ok = SleepConditionVariableSRW(&cv->cv, cv->srl, msec, 0); return (ok ? 0 : NNG_ETIMEDOUT); } @@ -156,23 +153,16 @@ nni_plat_thr_fini(nni_plat_thr *thr) int nni_plat_init(int (*helper)(void)) { - LONG old; - static LONG initing = 0; static LONG inited = 0; int rv; + static SRWLOCK lock = SRWLOCK_INIT; if (inited) { return (0); // fast path } - // This logic gets us to initialize the platform just once. - // If two threads enter here together, only one will get to run, - // and the other will be put to sleep briefly so that the first - // can complete. This is a poor man's singleton initializer, since - // we can't statically initialize critical sections. - while ((old = InterlockedCompareExchange(&initing, 0, 1)) != 0) { - Sleep(1); - } + AcquireSRWLockExclusive(&lock); + if (!inited) { WSADATA data; WORD ver; @@ -185,7 +175,6 @@ nni_plat_init(int (*helper)(void)) rv = NNG_EINVAL; goto out; } - printf("STARTING...\n"); if ((rv = nni_win_iocp_sysinit()) != 0) { goto out; } @@ -197,7 +186,7 @@ nni_plat_init(int (*helper)(void)) } out: - InterlockedExchange(&initing, 0); + ReleaseSRWLockExclusive(&lock); return (rv); } |
