diff options
author | Craig Tiller <ctiller@google.com> | 2015-07-16 08:42:31 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-07-16 08:42:31 -0700 |
commit | b0c13ad7698e577298f199007cc2d7a0a3049d1c (patch) | |
tree | 7de7ae2fdd5b3c7d38f2fd32fd9209c5c249d239 /src/core/iomgr | |
parent | ca83dc810924549f9279e73c93b3610c5189f21b (diff) |
Fix a leaked lock, and make a debug-only detection for this class of bug
Diffstat (limited to 'src/core/iomgr')
-rw-r--r-- | src/core/iomgr/pollset_multipoller_with_poll_posix.c | 3 | ||||
-rw-r--r-- | src/core/iomgr/pollset_posix.c | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index 7377a04817..0084e83953 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -72,7 +72,7 @@ static void multipoll_with_poll_pollset_add_fd(grpc_pollset *pollset, pollset_hdr *h = pollset->data.ptr; /* TODO(ctiller): this is O(num_fds^2); maybe switch to a hash set here */ for (i = 0; i < h->fd_count; i++) { - if (h->fds[i] == fd) return; + if (h->fds[i] == fd) goto exit; } if (h->fd_count == h->fd_capacity) { h->fd_capacity = GPR_MAX(h->fd_capacity + 8, h->fd_count * 3 / 2); @@ -80,6 +80,7 @@ static void multipoll_with_poll_pollset_add_fd(grpc_pollset *pollset, } h->fds[h->fd_count++] = fd; GRPC_FD_REF(fd, "multipoller"); +exit: if (and_unlock_pollset) { gpr_mu_unlock(&pollset->mu); } diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index e8189c28ad..3c35fcb89f 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -106,11 +106,21 @@ void grpc_pollset_init(grpc_pollset *pollset) { void grpc_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) { gpr_mu_lock(&pollset->mu); pollset->vtable->add_fd(pollset, fd, 1); +#ifndef NDEBUG + /* this will deadlock if the unlocking rules aren't correctly implemented */ + gpr_mu_lock(&pollset->mu); + gpr_mu_unlock(&pollset->mu); +#endif } void grpc_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) { gpr_mu_lock(&pollset->mu); pollset->vtable->del_fd(pollset, fd, 1); +#ifndef NDEBUG + /* this will deadlock if the unlocking rules aren't correctly implemented */ + gpr_mu_lock(&pollset->mu); + gpr_mu_unlock(&pollset->mu); +#endif } static void finish_shutdown(grpc_pollset *pollset) { |