From e8309dcaa3e542e0b3c1f9d4c937314517cc27c5 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 22 Jun 2017 17:29:14 -0700 Subject: Don't acquire the lock if the endpoint isn't on a list. --- src/core/socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/socket.c b/src/core/socket.c index 195bbcf3..2c20705a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -642,12 +642,14 @@ nni_sock_add_ep(nni_sock *sock, nni_ep *ep) void nni_sock_rem_ep(nni_sock *sock, nni_ep *ep) { - nni_mtx_lock(&sock->s_mx); // If we're not on the list, then nothing to do. Be idempotent. - if (!nni_list_active(&sock->s_eps, ep)) { - nni_mtx_unlock(&sock->s_mx); + // Note that if the ep is not on a list, then we assume that we have + // exclusive access. Therefore the check for being active need not + // be locked. + if ((sock == NULL) || (!nni_list_active(&sock->s_eps, ep))) { return; } + nni_mtx_lock(&sock->s_mx); nni_list_remove(&sock->s_eps, ep); nni_mtx_unlock(&sock->s_mx); -- cgit v1.2.3-70-g09d2