diff --git a/src/core/iomgr/pollset_windows.c b/src/core/iomgr/pollset_windows.c index 926ee8fdd90..8d6bc79c96c 100644 --- a/src/core/iomgr/pollset_windows.c +++ b/src/core/iomgr/pollset_windows.c @@ -48,6 +48,7 @@ won't actually do any polling, and return as quickly as possible. */ void grpc_pollset_init(grpc_pollset *pollset) { + memset(pollset, 0, sizeof(*pollset)); gpr_mu_init(&pollset->mu); gpr_cv_init(&pollset->cv); } @@ -55,7 +56,10 @@ void grpc_pollset_init(grpc_pollset *pollset) { void grpc_pollset_shutdown(grpc_pollset *pollset, void (*shutdown_done)(void *arg), void *shutdown_done_arg) { - grpc_pollset_kick(pollset); + gpr_mu_lock(&pollset->mu); + pollset->shutting_down = 1; + gpr_cv_broadcast(&pollset->cv); + gpr_mu_unlock(&pollset->mu); shutdown_done(shutdown_done_arg); } @@ -76,7 +80,9 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) { if (grpc_alarm_check(&pollset->mu, now, &deadline)) { return 1 /* GPR_TRUE */; } - gpr_cv_wait(&pollset->cv, &pollset->mu, deadline); + if (!pollset->shutting_down) { + gpr_cv_wait(&pollset->cv, &pollset->mu, deadline); + } return 1 /* GPR_TRUE */; } diff --git a/src/core/iomgr/pollset_windows.h b/src/core/iomgr/pollset_windows.h index b4aec1b8098..57a29079266 100644 --- a/src/core/iomgr/pollset_windows.h +++ b/src/core/iomgr/pollset_windows.h @@ -46,6 +46,7 @@ typedef struct grpc_pollset { gpr_mu mu; gpr_cv cv; + int shutting_down; } grpc_pollset; #define GRPC_POLLSET_MU(pollset) (&(pollset)->mu) diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index 063a23cfb18..bd0fabf9dac 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -208,7 +208,6 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, } if (cc->shutdown) { ev = create_shutdown_event(); - grpc_pollset_kick(&cc->pollset); break; } if (!grpc_pollset_work(&cc->pollset, deadline)) {