aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-06-22 17:29:14 -0700
committerGarrett D'Amore <garrett@damore.org>2017-06-22 17:29:14 -0700
commite8309dcaa3e542e0b3c1f9d4c937314517cc27c5 (patch)
tree416dd2e0300b01c6f2d2c1f2c5b882c0ffe939c6
parent34b110779fc29e82fc4bc4d48848d17a86fc2c26 (diff)
downloadnng-e8309dcaa3e542e0b3c1f9d4c937314517cc27c5.tar.gz
nng-e8309dcaa3e542e0b3c1f9d4c937314517cc27c5.tar.bz2
nng-e8309dcaa3e542e0b3c1f9d4c937314517cc27c5.zip
Don't acquire the lock if the endpoint isn't on a list.
-rw-r--r--src/core/socket.c8
1 files changed, 5 insertions, 3 deletions
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);