From 85593e678c35c13ed2d37f7f22aa41b0b8d70825 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 12 Jul 2017 18:02:22 -0700 Subject: Attempts to minimize races, remove unused nni_sock_mtx function. We still have endpoint related races apparently; we need to examine the possibility of handling endpoints much like we do pipes, which seem to be race free. --- src/core/socket.c | 18 ++++++------------ src/core/socket.h | 8 -------- src/platform/windows/win_ipc.c | 1 + 3 files changed, 7 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/core/socket.c b/src/core/socket.c index c561b719..4be5a856 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -218,12 +218,6 @@ nni_sock_unnotify(nni_sock *sock, nni_notify *notify) NNI_FREE_STRUCT(notify); } -nni_mtx * -nni_sock_mtx(nni_sock *sock) -{ - return (&sock->s_mx); -} - static nni_msg * nni_sock_nullfilter(void *arg, nni_msg *mp) { @@ -509,6 +503,12 @@ nni_sock_shutdown(nni_sock *sock) nni_ep_close(ep); } + // Wait for the pipes to be reaped (there should not be any because + // we have already reaped the EPs.) + while ((pipe = nni_list_first(&sock->s_pipes)) != NULL) { + nni_cv_wait(&sock->s_cv); + } + // Wait for the eps to be reaped. while ((ep = nni_list_first(&sock->s_eps)) != NULL) { nni_list_remove(&sock->s_eps, ep); @@ -521,12 +521,6 @@ nni_sock_shutdown(nni_sock *sock) nni_mtx_lock(&sock->s_mx); } - // Wait for the pipes to be reaped (there should not be any because - // we have already reaped the EPs.) - while ((pipe = nni_list_first(&sock->s_pipes)) != NULL) { - nni_cv_wait(&sock->s_cv); - } - sock->s_sock_ops.sock_close(sock->s_data); nni_cv_wake(&sock->s_cv); diff --git a/src/core/socket.h b/src/core/socket.h index c4619b42..76b57f09 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -113,14 +113,6 @@ extern nni_msgq *nni_sock_sendq(nni_sock *); // inject incoming messages from pipes to it. extern nni_msgq *nni_sock_recvq(nni_sock *); -// nni_sock_mtx obtains the socket mutex. This is for protocols to use -// from separate threads; they must not hold the lock for extended periods. -// Additionally, this can only be acquired from separate threads. The -// synchronous entry points (excluding the send/recv thread workers) will -// be called with this lock already held. We expose the mutex directly -// here so that protocols can use it to initialize condvars. -extern nni_mtx *nni_sock_mtx(nni_sock *); - extern nni_duration nni_sock_linger(nni_sock *); extern size_t nni_sock_rcvmaxsz(nni_sock *); extern void nni_sock_reconntimes(nni_sock *, nni_duration *, nni_duration *); diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c index be1a98a1..dff65941 100644 --- a/src/platform/windows/win_ipc.c +++ b/src/platform/windows/win_ipc.c @@ -528,6 +528,7 @@ nni_plat_ipc_ep_connect(nni_plat_ipc_ep *ep, nni_aio *aio) void nni_plat_ipc_ep_fini(nni_plat_ipc_ep *ep) { + nni_plat_ipc_ep_close(ep); if (ep->p != INVALID_HANDLE_VALUE) { CloseHandle(ep->p); ep->p = NULL; -- cgit v1.2.3-70-g09d2