diff options
Diffstat (limited to 'src/core/lib/iomgr/iomgr.cc')
-rw-r--r-- | src/core/lib/iomgr/iomgr.cc | 115 |
1 files changed, 57 insertions, 58 deletions
diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index dacf08ea9e..e077b35014 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -45,20 +45,20 @@ static gpr_cv g_rcv; static int g_shutdown; static grpc_iomgr_object g_root_object; -void grpc_iomgr_init() { - grpc_core::ExecCtx exec_ctx; +void grpc_iomgr_init(grpc_exec_ctx* exec_ctx) { g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); - grpc_executor_init(); - grpc_timer_list_init(); + grpc_exec_ctx_global_init(); + grpc_executor_init(exec_ctx); + grpc_timer_list_init(exec_ctx); g_root_object.next = g_root_object.prev = &g_root_object; g_root_object.name = (char*)"root"; grpc_network_status_init(); grpc_iomgr_platform_init(); } -void grpc_iomgr_start() { grpc_timer_manager_init(); } +void grpc_iomgr_start(grpc_exec_ctx* exec_ctx) { grpc_timer_manager_init(); } static size_t count_objects(void) { grpc_iomgr_object* obj; @@ -76,76 +76,75 @@ static void dump_objects(const char* kind) { } } -void grpc_iomgr_shutdown() { +void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) { gpr_timespec shutdown_deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)); gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME); - { - grpc_timer_manager_shutdown(); - grpc_iomgr_platform_flush(); - grpc_executor_shutdown(); - - gpr_mu_lock(&g_mu); - g_shutdown = 1; - while (g_root_object.next != &g_root_object) { - if (gpr_time_cmp( - gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), - gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { - if (g_root_object.next != &g_root_object) { - gpr_log(GPR_DEBUG, - "Waiting for %" PRIuPTR " iomgr objects to be destroyed", - count_objects()); - } - last_warning_time = gpr_now(GPR_CLOCK_REALTIME); + grpc_timer_manager_shutdown(); + grpc_iomgr_platform_flush(); + grpc_executor_shutdown(exec_ctx); + + gpr_mu_lock(&g_mu); + g_shutdown = 1; + while (g_root_object.next != &g_root_object) { + if (gpr_time_cmp( + gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), + gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { + if (g_root_object.next != &g_root_object) { + gpr_log(GPR_DEBUG, + "Waiting for %" PRIuPTR " iomgr objects to be destroyed", + count_objects()); } - grpc_core::ExecCtx::Get()->SetNowIomgrShutdown(); - if (grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED) { - gpr_mu_unlock(&g_mu); - grpc_core::ExecCtx::Get()->Flush(); - grpc_iomgr_platform_flush(); - gpr_mu_lock(&g_mu); - continue; + last_warning_time = gpr_now(GPR_CLOCK_REALTIME); + } + exec_ctx->now_is_valid = true; + exec_ctx->now = GRPC_MILLIS_INF_FUTURE; + if (grpc_timer_check(exec_ctx, nullptr) == GRPC_TIMERS_FIRED) { + gpr_mu_unlock(&g_mu); + grpc_exec_ctx_flush(exec_ctx); + grpc_iomgr_platform_flush(); + gpr_mu_lock(&g_mu); + continue; + } + if (g_root_object.next != &g_root_object) { + if (grpc_iomgr_abort_on_leaks()) { + gpr_log(GPR_DEBUG, + "Failed to free %" PRIuPTR + " iomgr objects before shutdown deadline: " + "memory leaks are likely", + count_objects()); + dump_objects("LEAKED"); + abort(); } - if (g_root_object.next != &g_root_object) { - if (grpc_iomgr_abort_on_leaks()) { - gpr_log(GPR_DEBUG, - "Failed to free %" PRIuPTR - " iomgr objects before shutdown deadline: " - "memory leaks are likely", - count_objects()); - dump_objects("LEAKED"); - abort(); - } - gpr_timespec short_deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_millis(100, GPR_TIMESPAN)); - if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { - if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > - 0) { - if (g_root_object.next != &g_root_object) { - gpr_log(GPR_DEBUG, - "Failed to free %" PRIuPTR - " iomgr objects before shutdown deadline: " - "memory leaks are likely", - count_objects()); - dump_objects("LEAKED"); - } - break; + gpr_timespec short_deadline = gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN)); + if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { + if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) { + if (g_root_object.next != &g_root_object) { + gpr_log(GPR_DEBUG, + "Failed to free %" PRIuPTR + " iomgr objects before shutdown deadline: " + "memory leaks are likely", + count_objects()); + dump_objects("LEAKED"); } + break; } } } - gpr_mu_unlock(&g_mu); - grpc_timer_list_shutdown(); - grpc_core::ExecCtx::Get()->Flush(); } + gpr_mu_unlock(&g_mu); + + grpc_timer_list_shutdown(exec_ctx); + grpc_exec_ctx_flush(exec_ctx); /* ensure all threads have left g_mu */ gpr_mu_lock(&g_mu); gpr_mu_unlock(&g_mu); grpc_iomgr_platform_shutdown(); + grpc_exec_ctx_global_shutdown(); grpc_network_status_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_rcv); |