Skip to content
Snippets Groups Projects
Commit 966a448a authored by Dan Born's avatar Dan Born
Browse files

Require non-NULL exec_ctx to unref.

parent 930c2983
No related branches found
No related tags found
No related merge requests found
...@@ -101,8 +101,8 @@ grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s); ...@@ -101,8 +101,8 @@ grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s);
void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s, void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s,
grpc_closure *shutdown_starting); grpc_closure *shutdown_starting);
/* If the refcount drops to zero, delete s, and call (exec_ctx==NULL) or enqueue /* If the refcount drops to zero, enqueue calls on exec_ctx to
a call (exec_ctx!=NULL) to shutdown_complete. */ shutdown_listeners and delete s. */
void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s); void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s);
/* Shutdown the fds of listeners. */ /* Shutdown the fds of listeners. */
......
...@@ -745,22 +745,11 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s, ...@@ -745,22 +745,11 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s,
void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
if (gpr_unref(&s->refs)) { if (gpr_unref(&s->refs)) {
grpc_exec_ctx local_exec_ctx = GRPC_EXEC_CTX_INIT;
bool finish_ctx = false;
/* FIXME: API allows a NULL exec_ctx, although this might cause us to delete
ourself before some enqueued work in some other exec_ctx runs. */
if (exec_ctx == NULL) {
exec_ctx = &local_exec_ctx;
finish_ctx = true;
}
grpc_tcp_server_shutdown_listeners(exec_ctx, s); grpc_tcp_server_shutdown_listeners(exec_ctx, s);
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
grpc_exec_ctx_enqueue_list(exec_ctx, &s->shutdown_starting, NULL); grpc_exec_ctx_enqueue_list(exec_ctx, &s->shutdown_starting, NULL);
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
tcp_server_destroy(exec_ctx, s); tcp_server_destroy(exec_ctx, s);
if (finish_ctx) {
grpc_exec_ctx_finish(exec_ctx);
}
} }
} }
......
...@@ -121,6 +121,9 @@ grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete, ...@@ -121,6 +121,9 @@ grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete,
} }
static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
gpr_mu_lock(&s->mu);
GPR_ASSERT(s->shutdown);
gpr_mu_unlock(&s->mu);
if (s->shutdown_complete != NULL) { if (s->shutdown_complete != NULL) {
grpc_exec_ctx_sched(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE, NULL); grpc_exec_ctx_sched(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE, NULL);
} }
...@@ -139,7 +142,7 @@ static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { ...@@ -139,7 +142,7 @@ static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
} }
grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s) { grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s) {
gpr_ref(&s->refs); gpr_ref_non_zero(&s->refs);
return s; return s;
} }
...@@ -174,19 +177,11 @@ static void tcp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { ...@@ -174,19 +177,11 @@ static void tcp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
if (gpr_unref(&s->refs)) { if (gpr_unref(&s->refs)) {
/* Complete shutdown_starting work before destroying. */ grpc_tcp_server_shutdown_listeners(exec_ctx, s);
grpc_exec_ctx local_exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
grpc_exec_ctx_enqueue_list(&local_exec_ctx, &s->shutdown_starting, NULL); grpc_exec_ctx_enqueue_list(exec_ctx, &s->shutdown_starting, NULL);
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
if (exec_ctx == NULL) { tcp_server_destroy(exec_ctx, s);
grpc_exec_ctx_flush(&local_exec_ctx);
tcp_server_destroy(&local_exec_ctx, s);
grpc_exec_ctx_finish(&local_exec_ctx);
} else {
grpc_exec_ctx_finish(&local_exec_ctx);
tcp_server_destroy(exec_ctx, s);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment