From fe3c9705072ac8cafecdf2ea6bca4c26f9464824 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 28 Jun 2017 23:07:28 -0700 Subject: Refactor stop again, closing numerous races (thanks valgrind!) --- src/core/endpt.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/core/endpt.c') diff --git a/src/core/endpt.c b/src/core/endpt.c index 74bd0314..e3f78ecd 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -203,14 +203,7 @@ nni_ep_stop(nni_ep *ep) void nni_ep_close(nni_ep *ep) { - nni_pipe *pipe; - nni_ep_stop(ep); - nni_mtx_lock(&ep->ep_mtx); - NNI_LIST_FOREACH (&ep->ep_pipes, pipe) { - nni_pipe_close(pipe); - } - nni_mtx_unlock(&ep->ep_mtx); } @@ -220,7 +213,15 @@ nni_ep_remove(nni_ep *ep) nni_pipe *pipe; nni_sock *sock = ep->ep_sock; - nni_ep_close(ep); + nni_ep_stop(ep); + + nni_thr_wait(&ep->ep_thr); + + nni_mtx_lock(&ep->ep_mtx); + NNI_LIST_FOREACH (&ep->ep_pipes, pipe) { + nni_pipe_close(pipe); + } + nni_mtx_unlock(&ep->ep_mtx); nni_mtx_lock(&ep->ep_mtx); while (nni_list_first(&ep->ep_pipes) != NULL) { -- cgit v1.2.3-70-g09d2