From 75122c23578e24417dcf64081c737571a9fc2dbc Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 13 Nov 2017 15:37:58 -0800 Subject: Address some PR comments --- .../ext/filters/client_channel/backup_poller.cc | 6 ++-- .../filters/client_channel/channel_connectivity.cc | 6 ++-- .../client_channel/lb_policy/grpclb/grpclb.cc | 8 ++--- .../resolver/dns/c_ares/dns_resolver_ares.cc | 2 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 14 +-------- .../resolver/dns/native/dns_resolver.cc | 2 +- src/core/ext/filters/client_channel/subchannel.cc | 2 +- .../ext/filters/client_channel/subchannel_index.cc | 36 +++++++++++----------- src/core/ext/filters/max_age/max_age_filter.cc | 6 ++-- 9 files changed, 34 insertions(+), 48 deletions(-) (limited to 'src/core/ext/filters') diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index 1b42f5d6a0..dbdcd53ef5 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -112,10 +112,10 @@ static void run_poller(void* arg, grpc_error* error) { backup_poller_shutdown_unref(p); return; } - grpc_error* err = grpc_pollset_work(p->pollset, NULL, grpc_exec_ctx_now()); + grpc_error* err = grpc_pollset_work(p->pollset, NULL, ExecCtx::Get()->Now()); gpr_mu_unlock(p->pollset_mu); GRPC_LOG_IF_ERROR("Run client channel backup poller", err); - grpc_timer_init(&p->polling_timer, grpc_exec_ctx_now() + g_poll_interval_ms, + grpc_timer_init(&p->polling_timer, ExecCtx::Get()->Now() + g_poll_interval_ms, &p->run_poller_closure); } @@ -137,7 +137,7 @@ void grpc_client_channel_start_backup_polling( GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, grpc_schedule_on_exec_ctx); grpc_timer_init(&g_poller->polling_timer, - grpc_exec_ctx_now() + g_poll_interval_ms, + ExecCtx::Get()->Now() + g_poll_interval_ms, &g_poller->run_poller_closure); } diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 3069e66775..0ceedb9f86 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -41,14 +41,14 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( if (client_channel_elem->filter == &grpc_client_channel_filter) { state = grpc_client_channel_check_connectivity_state(client_channel_elem, try_to_connect); - grpc_exec_ctx_finish(); + return state; } gpr_log(GPR_ERROR, "grpc_channel_check_connectivity_state called on something that is " "not a client channel, but '%s'", client_channel_elem->filter->name); - grpc_exec_ctx_finish(); + return GRPC_CHANNEL_SHUTDOWN; } @@ -241,6 +241,4 @@ void grpc_channel_watch_connectivity_state( } else { abort(); } - - grpc_exec_ctx_finish(); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index d4c58fb1e0..63cf417c4e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -1122,7 +1122,7 @@ static void start_picking_locked(glb_lb_policy* glb_policy) { if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->serverlist == NULL && !glb_policy->fallback_timer_active) { grpc_millis deadline = - grpc_exec_ctx_now() + glb_policy->lb_fallback_timeout_ms; + ExecCtx::Get()->Now() + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); GRPC_CLOSURE_INIT(&glb_policy->lb_on_fallback, lb_on_fallback_timer_locked, glb_policy, @@ -1271,7 +1271,7 @@ static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", glb_policy); - grpc_millis timeout = next_try - grpc_exec_ctx_now(); + grpc_millis timeout = next_try - ExecCtx::Get()->Now(); if (timeout > 0) { gpr_log(GPR_DEBUG, "[grpclb %p] ... retry_timer_active in %" PRIuPTR "ms.", @@ -1297,7 +1297,7 @@ static void send_client_load_report_locked(void* arg, grpc_error* error); static void schedule_next_client_load_report(glb_lb_policy* glb_policy) { const grpc_millis next_client_load_report_time = - grpc_exec_ctx_now() + glb_policy->client_stats_report_interval; + ExecCtx::Get()->Now() + glb_policy->client_stats_report_interval; GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, send_client_load_report_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); @@ -1392,7 +1392,7 @@ static void lb_call_init_locked(glb_lb_policy* glb_policy) { grpc_millis deadline = glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE - : grpc_exec_ctx_now() + glb_policy->lb_call_timeout_ms; + : ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 77d790aa38..f0543964ae 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -265,7 +265,7 @@ static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); grpc_millis next_try = grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_exec_ctx_now(); + grpc_millis timeout = next_try - ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index c57fac61a4..925223d189 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -101,18 +101,7 @@ static void grpc_ares_request_unref(grpc_ares_request* r) { request */ if (gpr_unref(&r->pending_queries)) { /* TODO(zyc): Sort results with RFC6724 before invoking on_done. */ - if (exec_ctx == NULL) { - /* A new exec_ctx is created here, as the c-ares interface does not - provide one in ares_host_callback. It's safe to schedule on_done with - the newly created exec_ctx, since the caller has been warned not to - acquire locks in on_done. ares_dns_resolver is using combiner to - protect resources needed by on_done. */ - ExecCtx _local_exec_ctx; - GRPC_CLOSURE_SCHED(r->on_done, r->error); - grpc_exec_ctx_finish(); - } else { - GRPC_CLOSURE_SCHED(r->on_done, r->error); - } + GRPC_CLOSURE_SCHED(r->on_done, r->error); gpr_mu_destroy(&r->mu); grpc_ares_ev_driver_destroy(r->ev_driver); gpr_free(r); @@ -263,7 +252,6 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, } } grpc_ares_request_unref(r); - grpc_exec_ctx_finish(); } static const char g_service_config_attribute_prefix[] = "grpc_config="; diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index 4463673e1f..10404ec4ef 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -163,7 +163,7 @@ static void dns_on_resolved_locked(void* arg, grpc_error* error) { } else { grpc_millis next_try = grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_exec_ctx_now(); + grpc_millis timeout = next_try - ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index c8583687d5..98f96b5750 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -458,7 +458,7 @@ static void maybe_start_connecting_locked(grpc_subchannel* c) { GPR_ASSERT(!c->have_alarm); c->have_alarm = true; const grpc_millis time_til_next = - c->backoff_result.next_attempt_start_time - grpc_exec_ctx_now(); + c->backoff_result.next_attempt_start_time - ExecCtx::Get()->Now(); if (time_til_next <= 0) { gpr_log(GPR_INFO, "Retry immediately"); } else { diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index cb8e480734..fbab57769c 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -132,10 +132,8 @@ void grpc_subchannel_index_shutdown(void) { void grpc_subchannel_index_unref(void) { if (gpr_unref(&g_refcount)) { - ExecCtx _local_exec_ctx; gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_subchannel_index, exec_ctx); - grpc_exec_ctx_finish(); + gpr_avl_unref(g_subchannel_index, ExecCtx::Get()); } } @@ -145,12 +143,12 @@ grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key) { // Lock, and take a reference to the subchannel index. // We don't need to do the search under a lock as avl's are immutable. gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); gpr_mu_unlock(&g_mu); grpc_subchannel* c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( - (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx), "index_find"); - gpr_avl_unref(index, exec_ctx); + (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()), "index_find"); + gpr_avl_unref(index, ExecCtx::Get()); return c; } @@ -166,11 +164,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); + c = (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()); if (c != NULL) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -180,8 +178,9 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, } else { // no -> update the avl and compare/swap gpr_avl updated = gpr_avl_add( - gpr_avl_ref(index, exec_ctx), subchannel_key_copy(key), - GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), exec_ctx); + gpr_avl_ref(index, ExecCtx::Get()), subchannel_key_copy(key), + GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), + ExecCtx::Get()); // it may happen (but it's expected to be unlikely) // that some other thread has changed the index: @@ -193,9 +192,9 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, exec_ctx); + gpr_avl_unref(updated, ExecCtx::Get()); } - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, ExecCtx::Get()); } if (need_to_unref_constructed) { @@ -212,21 +211,22 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); gpr_mu_unlock(&g_mu); // Check to see if this key still refers to the previously // registered subchannel - grpc_subchannel* c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); + grpc_subchannel* c = + (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()); if (c != constructed) { - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, ExecCtx::Get()); break; } // compare and swap the update (some other thread may have // mutated the index behind us) gpr_avl updated = - gpr_avl_remove(gpr_avl_ref(index, exec_ctx), key, exec_ctx); + gpr_avl_remove(gpr_avl_ref(index, ExecCtx::Get()), key, ExecCtx::Get()); gpr_mu_lock(&g_mu); if (index.root == g_subchannel_index.root) { @@ -235,8 +235,8 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, exec_ctx); - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(updated, ExecCtx::Get()); + gpr_avl_unref(index, ExecCtx::Get()); } } diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 1b9ce3b996..015a3ce124 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -100,7 +100,7 @@ static void decrease_call_count(channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, -1) == 1) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); grpc_timer_init(&chand->max_idle_timer, - grpc_exec_ctx_now() + chand->max_connection_idle, + ExecCtx::Get()->Now() + chand->max_connection_idle, &chand->close_max_idle_channel); } } @@ -121,7 +121,7 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* error) { chand->max_age_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); grpc_timer_init(&chand->max_age_timer, - grpc_exec_ctx_now() + chand->max_connection_age, + ExecCtx::Get()->Now() + chand->max_connection_age, &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(NULL); @@ -141,7 +141,7 @@ static void start_max_age_grace_timer_after_goaway_op(void* arg, grpc_timer_init(&chand->max_age_grace_timer, chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE ? GRPC_MILLIS_INF_FUTURE - : grpc_exec_ctx_now() + chand->max_connection_age_grace, + : ExecCtx::Get()->Now() + chand->max_connection_age_grace, &chand->force_close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, -- cgit v1.2.3