aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2017-02-15 18:31:57 -0800
committerGravatar Sree Kuchibhotla <sreek@google.com>2017-02-15 18:31:57 -0800
commitfb7ced6416357b86bc318fe6d460f56becf7c3b4 (patch)
tree64be3a8185b324dcf1ab181bb811497614bb427f /src/core/lib/iomgr
parent7889f24e49053bd63ec27e11eb368eb204497f1a (diff)
use correct memory barriers
Diffstat (limited to 'src/core/lib/iomgr')
-rw-r--r--src/core/lib/iomgr/ev_epoll_linux.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c
index 108cf5a613..2a0b8917e8 100644
--- a/src/core/lib/iomgr/ev_epoll_linux.c
+++ b/src/core/lib/iomgr/ev_epoll_linux.c
@@ -1108,7 +1108,9 @@ static void notify_on(grpc_exec_ctx *exec_ctx, grpc_fd *fd, gpr_atm *state,
grpc_closure *closure) {
while (true) {
/* Fast-path: CLOSURE_NOT_READY -> <closure> */
- if (gpr_atm_acq_cas(state, CLOSURE_NOT_READY, (gpr_atm)closure)) {
+ /* Also do a release-cas here so that there is a 'happen-before' established
+ with acquire loads in set_ready() / set_shutdown() */
+ if (gpr_atm_rel_cas(state, CLOSURE_NOT_READY, (gpr_atm)closure)) {
return; /* Fast-path successful. Return */
}
@@ -1163,7 +1165,7 @@ static void set_shutdown(grpc_exec_ctx *exec_ctx, grpc_fd *fd, gpr_atm *state,
gpr_atm new_state = (gpr_atm)shutdown_err | FD_SHUTDOWN_BIT;
while (true) {
- if (gpr_atm_acq_cas(state, curr, new_state)) {
+ if (gpr_atm_rel_cas(state, curr, new_state)) {
return; /* Fast-path successful. Return */
}
@@ -1206,9 +1208,9 @@ static void set_shutdown(grpc_exec_ctx *exec_ctx, grpc_fd *fd, gpr_atm *state,
}
static void set_ready(grpc_exec_ctx *exec_ctx, grpc_fd *fd, gpr_atm *state) {
- /* Try the fast-path first (i.e expect the current value to be
- * CLOSURE_NOT_READY */
- if (gpr_atm_acq_cas(state, CLOSURE_NOT_READY, CLOSURE_READY)) {
+ /* Try an optimistic case first (i.e assume current state is
+ CLOSURE_NOT_READY) */
+ if (gpr_atm_rel_cas(state, CLOSURE_NOT_READY, CLOSURE_READY)) {
return; /* early out */
}
@@ -1247,7 +1249,7 @@ static void set_ready(grpc_exec_ctx *exec_ctx, grpc_fd *fd, gpr_atm *state) {
static grpc_pollset *fd_get_read_notifier_pollset(grpc_exec_ctx *exec_ctx,
grpc_fd *fd) {
- gpr_atm notifier = gpr_atm_no_barrier_load(&fd->read_closure);
+ gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset);
return (grpc_pollset *)notifier;
}
@@ -1259,7 +1261,7 @@ static bool fd_is_shutdown(grpc_fd *fd) {
/* Might be called multiple times */
static void fd_shutdown(grpc_exec_ctx *exec_ctx, grpc_fd *fd, grpc_error *why) {
/* Store the shutdown error ORed with FD_SHUTDOWN_BIT in fd->shutdown_error */
- if (gpr_atm_acq_cas(&fd->shutdown_error, (gpr_atm)GRPC_ERROR_NONE,
+ if (gpr_atm_rel_cas(&fd->shutdown_error, (gpr_atm)GRPC_ERROR_NONE,
(gpr_atm)why | FD_SHUTDOWN_BIT)) {
shutdown(fd->fd, SHUT_RDWR);
@@ -1474,7 +1476,8 @@ static void fd_become_readable(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
sets (This can happen briefly during polling island merges). In such cases
it does not really matter which notifer is set as the read_notifier_pollset
(They would both point to the same polling island anyway) */
- gpr_atm_no_barrier_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
+ /* Use release store to match with acquire load in fd_get_read_notifier */
+ gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
}
static void fd_become_writable(grpc_exec_ctx *exec_ctx, grpc_fd *fd) {