aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@users.noreply.github.com>2016-03-22 13:55:27 -0700
committerGravatar Jan Tattermusch <jtattermusch@users.noreply.github.com>2016-03-22 13:55:27 -0700
commit3271dbc311635cd961bacf48ea8c33bd18cfa649 (patch)
treeef60b3ddab878237695b482752955307589dc8b4
parenta814c7dd9ce7f43cc5288d96cb220c82306ad3e1 (diff)
parentc6993428c271513dfe15c9ff6f823ca656fbcbd6 (diff)
Merge pull request #5896 from vjpai/i_know_freelists
Lock the FD when initializing it out of the freelist
-rw-r--r--src/core/iomgr/fd_posix.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c
index 3edafa0b07..b4d038a3a1 100644
--- a/src/core/iomgr/fd_posix.c
+++ b/src/core/iomgr/fd_posix.c
@@ -72,9 +72,6 @@ static grpc_fd *fd_freelist = NULL;
static gpr_mu fd_freelist_mu;
static void freelist_fd(grpc_fd *fd) {
- // Note that this function must be called after a release store (or
- // full-barrier operation) on refst so that prior actions on the fd are
- // ordered before the fd becomes visible to the freelist
gpr_mu_lock(&fd_freelist_mu);
fd->freelist_next = fd_freelist;
fd_freelist = fd;
@@ -95,6 +92,7 @@ static grpc_fd *alloc_fd(int fd) {
gpr_mu_init(&r->mu);
}
+ gpr_mu_lock(&r->mu);
r->shutdown = 0;
r->read_closure = CLOSURE_NOT_READY;
r->write_closure = CLOSURE_NOT_READY;
@@ -106,11 +104,9 @@ static grpc_fd *alloc_fd(int fd) {
r->on_done_closure = NULL;
r->closed = 0;
r->released = 0;
- // The last operation on r before returning it should be a release-store
- // so that all the above fields are globally visible before the value of
- // r could escape to another thread. Our refcount itself needs a release-store
- // so use this
gpr_atm_rel_store(&r->refst, 1);
+ gpr_mu_unlock(&r->mu);
+
return r;
}