From 493542f4446efe4b87d187d22901078a5de06fe8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 22 Jun 2015 16:00:36 -0700 Subject: [PATCH] Remove return status from maybe_work. Since alarm checks may mutate work deadlines for pollsets, the value returned from maybe_work is meaningless. Instead, maybe pollset_work always return 1 if maybe_work is invoked, and then redo the deadline check _on the next call_ to pollset_work. --- src/core/iomgr/pollset_multipoller_with_epoll.c | 3 +-- .../iomgr/pollset_multipoller_with_poll_posix.c | 8 +++----- src/core/iomgr/pollset_posix.c | 16 +++++++--------- src/core/iomgr/pollset_posix.h | 4 ++-- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/core/iomgr/pollset_multipoller_with_epoll.c b/src/core/iomgr/pollset_multipoller_with_epoll.c index b4a526b9e78..dcf08d379cb 100644 --- a/src/core/iomgr/pollset_multipoller_with_epoll.c +++ b/src/core/iomgr/pollset_multipoller_with_epoll.c @@ -83,7 +83,7 @@ static void multipoll_with_epoll_pollset_del_fd(grpc_pollset *pollset, /* TODO(klempner): We probably want to turn this down a bit */ #define GRPC_EPOLL_MAX_EVENTS 1000 -static int multipoll_with_epoll_pollset_maybe_work( +static void multipoll_with_epoll_pollset_maybe_work( grpc_pollset *pollset, gpr_timespec deadline, gpr_timespec now, int allow_synchronous_callback) { struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS]; @@ -133,7 +133,6 @@ static int multipoll_with_epoll_pollset_maybe_work( gpr_mu_lock(&pollset->mu); pollset->counter -= 1; - return 1; } static void multipoll_with_epoll_pollset_finish_shutdown( diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index 2f108da66a2..cc062693a96 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -103,7 +103,7 @@ static void end_polling(grpc_pollset *pollset) { } } -static int multipoll_with_poll_pollset_maybe_work( +static void multipoll_with_poll_pollset_maybe_work( grpc_pollset *pollset, gpr_timespec deadline, gpr_timespec now, int allow_synchronous_callback) { int timeout; @@ -126,7 +126,7 @@ static int multipoll_with_poll_pollset_maybe_work( kfd = grpc_pollset_kick_pre_poll(&pollset->kick_state); if (kfd == NULL) { /* Already kicked */ - return 1; + return; } h->pfds[0].fd = GRPC_POLLSET_KICK_GET_FD(kfd); h->pfds[0].events = POLLIN; @@ -154,7 +154,7 @@ static int multipoll_with_poll_pollset_maybe_work( h->del_count = 0; if (h->pfd_count == 0) { end_polling(pollset); - return 0; + return; } pollset->counter++; gpr_mu_unlock(&pollset->mu); @@ -191,8 +191,6 @@ static int multipoll_with_poll_pollset_maybe_work( gpr_mu_lock(&pollset->mu); pollset->counter--; - - return 1; } static void multipoll_with_poll_pollset_kick(grpc_pollset *p) { diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 46d3d132ce7..15ed8e75e6c 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -123,7 +123,6 @@ static void finish_shutdown(grpc_pollset *pollset) { int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) { /* pollset->mu already held */ gpr_timespec now = gpr_now(); - int r; if (gpr_time_cmp(now, deadline) > 0) { return 0; } @@ -137,7 +136,7 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) { return 1; } gpr_tls_set(&g_current_thread_poller, (gpr_intptr)pollset); - r = pollset->vtable->maybe_work(pollset, deadline, now, 1); + pollset->vtable->maybe_work(pollset, deadline, now, 1); gpr_tls_set(&g_current_thread_poller, 0); if (pollset->shutting_down) { if (pollset->counter > 0) { @@ -153,7 +152,7 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) { gpr_mu_lock(&pollset->mu); } } - return r; + return 1; } void grpc_pollset_shutdown(grpc_pollset *pollset, @@ -338,9 +337,9 @@ static void basic_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) { } } -static int basic_pollset_maybe_work(grpc_pollset *pollset, - gpr_timespec deadline, gpr_timespec now, - int allow_synchronous_callback) { +static void basic_pollset_maybe_work(grpc_pollset *pollset, + gpr_timespec deadline, gpr_timespec now, + int allow_synchronous_callback) { struct pollfd pfd[2]; grpc_fd *fd; grpc_fd_watcher fd_watcher; @@ -353,7 +352,7 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset, /* Give do_promote priority so we don't starve it out */ gpr_mu_unlock(&pollset->mu); gpr_mu_lock(&pollset->mu); - return 1; + return; } fd = pollset->data.ptr; if (fd && grpc_fd_is_orphaned(fd)) { @@ -364,7 +363,7 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset, kfd = grpc_pollset_kick_pre_poll(&pollset->kick_state); if (kfd == NULL) { /* Already kicked */ - return 1; + return; } pfd[0].fd = GRPC_POLLSET_KICK_GET_FD(kfd); pfd[0].events = POLLIN; @@ -418,7 +417,6 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset, gpr_mu_lock(&pollset->mu); pollset->counter--; - return 1; } static void basic_pollset_destroy(grpc_pollset *pollset) { diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h index ba3d638d41f..53585a28865 100644 --- a/src/core/iomgr/pollset_posix.h +++ b/src/core/iomgr/pollset_posix.h @@ -68,8 +68,8 @@ typedef struct grpc_pollset { struct grpc_pollset_vtable { void (*add_fd)(grpc_pollset *pollset, struct grpc_fd *fd); void (*del_fd)(grpc_pollset *pollset, struct grpc_fd *fd); - int (*maybe_work)(grpc_pollset *pollset, gpr_timespec deadline, - gpr_timespec now, int allow_synchronous_callback); + void (*maybe_work)(grpc_pollset *pollset, gpr_timespec deadline, + gpr_timespec now, int allow_synchronous_callback); void (*kick)(grpc_pollset *pollset); void (*finish_shutdown)(grpc_pollset *pollset); void (*destroy)(grpc_pollset *pollset);