aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/iomgr
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-01-29 22:08:59 -0800
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-01-29 22:10:03 -0800
commitdb8f3745e2ef2903866b748dd384910e9de1664d (patch)
treee3ade3ca656e6167c116ee76b001f953f8dc48ba /src/core/iomgr
parentb24b50094c2eb6d617847ff957afcc58ac5c569c (diff)
Fix some TSAN reported errors
Diffstat (limited to 'src/core/iomgr')
-rw-r--r--src/core/iomgr/pollset_multipoller_with_poll_posix.c7
-rw-r--r--src/core/iomgr/pollset_posix.c12
-rw-r--r--src/core/iomgr/pollset_posix.h4
3 files changed, 15 insertions, 8 deletions
diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c
index 7c9a9491cb..e88296979d 100644
--- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c
+++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c
@@ -147,8 +147,6 @@ static int multipoll_with_poll_pollset_maybe_work(
grpc_fd_unref(h->fds[i]);
} else {
h->fds[nf++] = h->fds[i];
- h->pfds[np].events =
- grpc_fd_begin_poll(h->fds[i], pollset, POLLIN, POLLOUT);
h->selfds[np] = h->fds[i];
h->pfds[np].fd = h->fds[i]->fd;
h->pfds[np].revents = 0;
@@ -168,6 +166,11 @@ static int multipoll_with_poll_pollset_maybe_work(
pollset->counter = 1;
gpr_mu_unlock(&pollset->mu);
+ for (i = 1; i < np; i++) {
+ h->pfds[i].events =
+ grpc_fd_begin_poll(h->selfds[i], pollset, POLLIN, POLLOUT);
+ }
+
r = poll(h->pfds, h->pfd_count, timeout);
if (r < 0) {
if (errno != EINTR) {
diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c
index 39e2dc4667..b1c2c64a18 100644
--- a/src/core/iomgr/pollset_posix.c
+++ b/src/core/iomgr/pollset_posix.c
@@ -75,11 +75,12 @@ static void backup_poller(void *p) {
}
void grpc_pollset_kick(grpc_pollset *p) {
- if (!p->counter) return;
- grpc_pollset_kick_kick(&p->kick_state);
+ if (p->counter) {
+ grpc_pollset_kick_kick(&p->kick_state);
+ }
}
-void grpc_pollset_force_kick(grpc_pollset *p) { grpc_pollset_kick(p); }
+void grpc_pollset_force_kick(grpc_pollset *p) { grpc_pollset_kick_kick(&p->kick_state); }
/* global state management */
@@ -244,11 +245,12 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
pfd[0].events = POLLIN;
pfd[0].revents = 0;
pfd[1].fd = fd->fd;
- pfd[1].events = grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT);
pfd[1].revents = 0;
pollset->counter = 1;
gpr_mu_unlock(&pollset->mu);
+ pfd[1].events = grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT);
+
r = poll(pfd, GPR_ARRAY_SIZE(pfd), timeout);
if (r < 0) {
if (errno != EINTR) {
@@ -269,9 +271,9 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
}
grpc_pollset_kick_post_poll(&pollset->kick_state);
+ grpc_fd_end_poll(fd, pollset);
gpr_mu_lock(&pollset->mu);
- grpc_fd_end_poll(fd, pollset);
pollset->counter = 0;
gpr_cv_broadcast(&pollset->cv);
return 1;
diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h
index f62433707e..3da025151d 100644
--- a/src/core/iomgr/pollset_posix.h
+++ b/src/core/iomgr/pollset_posix.h
@@ -78,7 +78,9 @@ void grpc_pollset_add_fd(grpc_pollset *pollset, struct grpc_fd *fd);
poll after an fd is orphaned) */
void grpc_pollset_del_fd(grpc_pollset *pollset, struct grpc_fd *fd);
-/* Force any current pollers to break polling */
+/* Force any current pollers to break polling: it's the callers responsibility
+ to ensure that the pollset indeed needs to be kicked.
+ Does not touch pollset->mu. */
void grpc_pollset_force_kick(grpc_pollset *pollset);
/* Returns the fd to listen on for kicks */
int grpc_kick_read_fd(grpc_pollset *p);