diff options
author | David Garcia Quintas <dgq@google.com> | 2015-05-28 16:27:39 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2015-05-31 12:48:44 -0700 |
commit | 284488b4347685a83f97b6123a8d7115bb8ee032 (patch) | |
tree | ab5c9a96ed3e0c38966f9db8fbb56673db20a76b /src/core | |
parent | 2738ae8c44786b8798d4b111e289b4baf1a134c6 (diff) |
removed managed closures from server.c
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/channel/child_channel.c | 16 | ||||
-rw-r--r-- | src/core/iomgr/iomgr.h | 1 | ||||
-rw-r--r-- | src/core/iomgr/pollset_posix.c | 10 | ||||
-rw-r--r-- | src/core/iomgr/tcp_posix.c | 8 | ||||
-rw-r--r-- | src/core/security/credentials.c | 1 | ||||
-rw-r--r-- | src/core/surface/call.c | 8 | ||||
-rw-r--r-- | src/core/surface/channel.c | 8 | ||||
-rw-r--r-- | src/core/surface/server.c | 45 |
8 files changed, 47 insertions, 50 deletions
diff --git a/src/core/channel/child_channel.c b/src/core/channel/child_channel.c index 213a4b881d..600f7df1bf 100644 --- a/src/core/channel/child_channel.c +++ b/src/core/channel/child_channel.c @@ -59,8 +59,8 @@ typedef struct { /* have we sent farewell (goaway + disconnect) */ gpr_uint8 sent_farewell; - grpc_iomgr_closure finally_destroy_channel_iocb; - grpc_iomgr_closure send_farewells_iocb; + grpc_iomgr_closure finally_destroy_channel_closure; + grpc_iomgr_closure send_farewells_closure; } lb_channel_data; typedef struct { grpc_child_channel *channel; } lb_call_data; @@ -216,16 +216,16 @@ static void maybe_destroy_channel(grpc_child_channel *channel) { lb_channel_data *chand = LINK_BACK_ELEM_FROM_CHANNEL(channel)->channel_data; if (chand->destroyed && chand->disconnected && chand->active_calls == 0 && !chand->sending_farewell && !chand->calling_back) { - chand->finally_destroy_channel_iocb.cb = finally_destroy_channel; - chand->finally_destroy_channel_iocb.cb_arg = channel; - grpc_iomgr_add_callback(&chand->finally_destroy_channel_iocb); + chand->finally_destroy_channel_closure.cb = finally_destroy_channel; + chand->finally_destroy_channel_closure.cb_arg = channel; + grpc_iomgr_add_callback(&chand->finally_destroy_channel_closure); } else if (chand->destroyed && !chand->disconnected && chand->active_calls == 0 && !chand->sending_farewell && !chand->sent_farewell) { chand->sending_farewell = 1; - chand->send_farewells_iocb.cb = send_farewells; - chand->send_farewells_iocb.cb_arg = channel; - grpc_iomgr_add_callback(&chand->send_farewells_iocb); + chand->send_farewells_closure.cb = send_farewells; + chand->send_farewells_closure.cb_arg = channel; + grpc_iomgr_add_callback(&chand->send_farewells_closure); } } diff --git a/src/core/iomgr/iomgr.h b/src/core/iomgr/iomgr.h index 437e8cf9a8..913f83f80e 100644 --- a/src/core/iomgr/iomgr.h +++ b/src/core/iomgr/iomgr.h @@ -47,6 +47,7 @@ typedef struct grpc_iomgr_closure { void grpc_iomgr_closure_init(grpc_iomgr_closure *closure, grpc_iomgr_cb_func cb, void *cb_arg); +/* TODO(dgq): get rid of the managed_closure concept. */ void grpc_iomgr_managed_closure_init(grpc_iomgr_closure *manager, grpc_iomgr_cb_func managed_cb, void *managed_cb_arg); diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index db17012df0..a8e6069002 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -257,7 +257,7 @@ typedef struct grpc_unary_promote_args { const grpc_pollset_vtable *original_vtable; grpc_pollset *pollset; grpc_fd *fd; - grpc_iomgr_closure promotion_iocb; + grpc_iomgr_closure promotion_closure; } grpc_unary_promote_args; static void unary_poll_do_promote(void *args, int success) { @@ -280,7 +280,7 @@ static void unary_poll_do_promote(void *args, int success) { /* First we need to ensure that nobody is polling concurrently */ while (pollset->counter != 0) { grpc_pollset_kick(pollset); - grpc_iomgr_add_callback(&up_args->promotion_iocb); + grpc_iomgr_add_callback(&up_args->promotion_closure); gpr_mu_unlock(&pollset->mu); return; } @@ -364,9 +364,9 @@ static void unary_poll_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) { up_args->pollset = pollset; up_args->fd = fd; up_args->original_vtable = pollset->vtable; - up_args->promotion_iocb.cb = unary_poll_do_promote; - up_args->promotion_iocb.cb_arg = up_args; - grpc_iomgr_add_callback(&up_args->promotion_iocb); + up_args->promotion_closure.cb = unary_poll_do_promote; + up_args->promotion_closure.cb_arg = up_args; + grpc_iomgr_add_callback(&up_args->promotion_closure); grpc_pollset_kick(pollset); } diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index 2978c2c370..2f19f9d442 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -281,7 +281,7 @@ typedef struct { grpc_iomgr_closure read_closure; grpc_iomgr_closure write_closure; - grpc_iomgr_closure handle_read_iocb; + grpc_iomgr_closure handle_read_closure; } grpc_tcp; static void grpc_tcp_handle_read(void *arg /* grpc_tcp */, int success); @@ -445,8 +445,8 @@ static void grpc_tcp_notify_on_read(grpc_endpoint *ep, grpc_endpoint_read_cb cb, tcp->finished_edge = 0; grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_closure); } else { - tcp->handle_read_iocb.cb_arg = tcp; - grpc_iomgr_add_callback(&tcp->handle_read_iocb); + tcp->handle_read_closure.cb_arg = tcp; + grpc_iomgr_add_callback(&tcp->handle_read_closure); } } @@ -596,7 +596,7 @@ grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd, size_t slice_size) { tcp->write_closure.cb = grpc_tcp_handle_write; tcp->write_closure.cb_arg = tcp; - tcp->handle_read_iocb.cb = grpc_tcp_handle_read; + tcp->handle_read_closure.cb = grpc_tcp_handle_read; return &tcp->base; } diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index 5e595899c3..a960e77db6 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -833,6 +833,7 @@ static void fake_oauth2_get_request_metadata(grpc_credentials *creds, if (c->is_async) { grpc_iomgr_closure *on_simulated_token_fetch_done_closure = gpr_malloc(sizeof(grpc_iomgr_closure)); + /* TODO(dgq): get rid of the managed_closure altogether */ grpc_iomgr_managed_closure_init( on_simulated_token_fetch_done_closure, on_simulated_token_fetch_done, grpc_credentials_metadata_request_create(creds, cb, user_data)); diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 3a739315a2..948d0cdc36 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -226,7 +226,7 @@ struct grpc_call { gpr_slice_buffer incoming_message; gpr_uint32 incoming_message_length; - grpc_iomgr_closure destroy_iocb; + grpc_iomgr_closure destroy_closure; }; #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1)) @@ -368,9 +368,9 @@ void grpc_call_internal_unref(grpc_call *c, int allow_immediate_deletion) { if (allow_immediate_deletion) { destroy_call(c, 1); } else { - c->destroy_iocb.cb = destroy_call; - c->destroy_iocb.cb_arg = c; - grpc_iomgr_add_callback(&c->destroy_iocb); + c->destroy_closure.cb = destroy_call; + c->destroy_closure.cb_arg = c; + grpc_iomgr_add_callback(&c->destroy_closure); } } } diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index d018db7bb0..947011c613 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -61,7 +61,7 @@ struct grpc_channel { gpr_mu registered_call_mu; registered_call *registered_calls; - grpc_iomgr_closure destroy_iocb; + grpc_iomgr_closure destroy_closure; }; #define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack *)((c) + 1)) @@ -194,9 +194,9 @@ static void destroy_channel(void *p, int ok) { void grpc_channel_internal_unref(grpc_channel *channel) { if (gpr_unref(&channel->refs)) { - channel->destroy_iocb.cb = destroy_channel; - channel->destroy_iocb.cb_arg = channel; - grpc_iomgr_add_callback(&channel->destroy_iocb); + channel->destroy_closure.cb = destroy_channel; + channel->destroy_closure.cb_arg = channel; + grpc_iomgr_add_callback(&channel->destroy_closure); } } diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 378d50486b..21b5f9162d 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -122,8 +122,8 @@ struct channel_data { channel_registered_method *registered_methods; gpr_uint32 registered_method_slots; gpr_uint32 registered_method_max_probes; - grpc_iomgr_closure finish_shutdown_channel_iocb; - grpc_iomgr_closure finish_destroy_channel_iocb; + grpc_iomgr_closure finish_shutdown_channel_closure; + grpc_iomgr_closure finish_destroy_channel_closure; }; struct grpc_server { @@ -180,6 +180,8 @@ struct call_data { void (*on_done_recv)(void *user_data, int success); void *recv_user_data; + grpc_iomgr_closure kill_zombie_closure; + call_data **root[CALL_LIST_COUNT]; call_link links[CALL_LIST_COUNT]; }; @@ -306,9 +308,9 @@ static void destroy_channel(channel_data *chand) { GPR_ASSERT(chand->server != NULL); orphan_channel(chand); server_ref(chand->server); - chand->finish_destroy_channel_iocb.cb = finish_destroy_channel; - chand->finish_destroy_channel_iocb.cb_arg = chand; - grpc_iomgr_add_callback(&chand->finish_destroy_channel_iocb); + chand->finish_destroy_channel_closure.cb = finish_destroy_channel; + chand->finish_destroy_channel_closure.cb_arg = chand; + grpc_iomgr_add_callback(&chand->finish_destroy_channel_closure); } static void finish_start_new_rpc_and_unlock(grpc_server *server, @@ -419,29 +421,24 @@ static void server_on_recv(void *ptr, int success) { case GRPC_STREAM_RECV_CLOSED: gpr_mu_lock(&chand->server->mu); if (calld->state == NOT_STARTED) { - grpc_iomgr_closure *kill_zombie_closure = - gpr_malloc(sizeof(grpc_iomgr_closure)); calld->state = ZOMBIED; - grpc_iomgr_managed_closure_init(kill_zombie_closure, kill_zombie, elem); - grpc_iomgr_add_callback(kill_zombie_closure); + grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem); + grpc_iomgr_add_callback(&calld->kill_zombie_closure); } gpr_mu_unlock(&chand->server->mu); break; case GRPC_STREAM_CLOSED: gpr_mu_lock(&chand->server->mu); if (calld->state == NOT_STARTED) { - grpc_iomgr_closure *kill_zombie_closure = - gpr_malloc(sizeof(grpc_iomgr_closure)); calld->state = ZOMBIED; - grpc_iomgr_managed_closure_init(kill_zombie_closure, kill_zombie, elem); - grpc_iomgr_add_callback(kill_zombie_closure); + grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem); + grpc_iomgr_add_callback(&calld->kill_zombie_closure); } else if (calld->state == PENDING) { - grpc_iomgr_closure *kill_zombie_closure = - gpr_malloc(sizeof(grpc_iomgr_closure)); call_list_remove(calld, PENDING_START); calld->state = ZOMBIED; - grpc_iomgr_managed_closure_init(kill_zombie_closure, kill_zombie, elem); - grpc_iomgr_add_callback(kill_zombie_closure); + grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem); + grpc_iomgr_add_callback(&calld->kill_zombie_closure); + } gpr_mu_unlock(&chand->server->mu); break; @@ -515,9 +512,9 @@ static void finish_shutdown_channel(void *cd, int success) { static void shutdown_channel(channel_data *chand) { grpc_channel_internal_ref(chand->channel); - chand->finish_shutdown_channel_iocb.cb = finish_shutdown_channel; - chand->finish_shutdown_channel_iocb.cb_arg = chand; - grpc_iomgr_add_callback(&chand->finish_shutdown_channel_iocb); + chand->finish_shutdown_channel_closure.cb = finish_shutdown_channel; + chand->finish_shutdown_channel_closure.cb_arg = chand; + grpc_iomgr_add_callback(&chand->finish_shutdown_channel_closure); } static void init_call_elem(grpc_call_element *elem, @@ -958,14 +955,12 @@ void grpc_server_destroy(grpc_server *server) { /* TODO(dgq): If we knew the size of the call list (or an upper bound), we * could allocate all the memory for the closures in advance in a single * chunk */ - grpc_iomgr_closure *kill_zombie_closure = - gpr_malloc(sizeof(grpc_iomgr_closure)); gpr_log(GPR_DEBUG, "server destroys call %p", calld->call); calld->state = ZOMBIED; - grpc_iomgr_managed_closure_init( - kill_zombie_closure, kill_zombie, + grpc_iomgr_closure_init( + &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0)); - grpc_iomgr_add_callback(kill_zombie_closure); + grpc_iomgr_add_callback(&calld->kill_zombie_closure); } for (c = server->root_channel_data.next; c != &server->root_channel_data; |