From ac80ef7c3b1caa2f1fe3b093bef825363675bcb3 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 26 Jun 2017 18:27:06 -0700 Subject: More race condition fixes. --- src/core/endpt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/core/endpt.c') diff --git a/src/core/endpt.c b/src/core/endpt.c index ab0d8cb9..74bd0314 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -253,7 +253,9 @@ nni_ep_connect(nni_ep *ep) nni_pipe_remove(pipe); return (rv); } + nni_mtx_lock(&ep->ep_mtx); ep->ep_pipe = pipe; + nni_mtx_unlock(&ep->ep_mtx); return (0); } @@ -277,17 +279,19 @@ nni_ep_pipe_add(nni_ep *ep, nni_pipe *pipe) void nni_ep_pipe_remove(nni_ep *ep, nni_pipe *pipe) { - if ((ep != NULL) && (nni_list_active(&ep->ep_pipes, pipe))) { - nni_mtx_lock(&ep->ep_mtx); + if (ep == NULL) { + return; + } + nni_mtx_lock(&ep->ep_mtx); + if (nni_list_active(&ep->ep_pipes, pipe)) { nni_list_remove(&ep->ep_pipes, pipe); if (ep->ep_pipe == pipe) { ep->ep_pipe = NULL; } nni_cv_wake(&ep->ep_cv); - - nni_mtx_unlock(&ep->ep_mtx); } + nni_mtx_unlock(&ep->ep_mtx); } -- cgit v1.2.3-70-g09d2