Skip to content

Commit

Permalink
Merge pull request grpc#2991 from murgatroid99/core_shutdown_idempotency
Browse files Browse the repository at this point in the history
Short-circuit shutdown when it is already published (core)
  • Loading branch information
soltanmm committed Aug 20, 2015
2 parents d7c27c6 + 00a3dab commit b714648
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/surface/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,11 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport,
grpc_transport_perform_op(transport, &op);
}

void done_published_shutdown(void *done_arg, grpc_cq_completion *storage) {
(void) done_arg;
gpr_free(storage);
}

void grpc_server_shutdown_and_notify(grpc_server *server,
grpc_completion_queue *cq, void *tag) {
listener *l;
Expand All @@ -986,6 +991,12 @@ void grpc_server_shutdown_and_notify(grpc_server *server,
/* lock, and gather up some stuff to do */
gpr_mu_lock(&server->mu_global);
grpc_cq_begin_op(cq);
if (server->shutdown_published) {
grpc_cq_end_op(cq, tag, 1, done_published_shutdown, NULL,
gpr_malloc(sizeof(grpc_cq_completion)));
gpr_mu_unlock(&server->mu_global);
return;
}
server->shutdown_tags =
gpr_realloc(server->shutdown_tags,
sizeof(shutdown_tag) * (server->num_shutdown_tags + 1));
Expand Down

0 comments on commit b714648

Please sign in to comment.