aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr/iomgr.cc
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2017-12-08 10:19:56 -0800
committerGravatar Sree Kuchibhotla <sreek@google.com>2017-12-08 10:19:56 -0800
commitca398ee74a7aed2a45ae58e3c5753c4c99e4d683 (patch)
tree0e49ba3759a117b66c598158d6ba745178a8ffce /src/core/lib/iomgr/iomgr.cc
parent54961bb9e16f84d193077277f7d2d8269f57a411 (diff)
parent94e676e10f8c739289924b8458a246699e3623ce (diff)
Merge branch 'master' into cv-wait-monotonic
Diffstat (limited to 'src/core/lib/iomgr/iomgr.cc')
-rw-r--r--src/core/lib/iomgr/iomgr.cc116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc
index bdedd85041..70807c479d 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_exec_ctx* exec_ctx) {
+void grpc_iomgr_init() {
+ grpc_core::ExecCtx exec_ctx;
g_shutdown = 0;
gpr_mu_init(&g_mu);
gpr_cv_init(&g_rcv);
- grpc_exec_ctx_global_init();
- grpc_executor_init(exec_ctx);
- grpc_timer_list_init(exec_ctx);
+ grpc_executor_init();
+ grpc_timer_list_init();
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_exec_ctx* exec_ctx) { grpc_timer_manager_init(); }
+void grpc_iomgr_start() { grpc_timer_manager_init(); }
static size_t count_objects(void) {
grpc_iomgr_object* obj;
@@ -76,76 +76,76 @@ static void dump_objects(const char* kind) {
}
}
-void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) {
+void grpc_iomgr_shutdown() {
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(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_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);
}
- 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();
+ 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;
}
- gpr_timespec short_deadline =
- gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- 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");
+ 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_MONOTONIC),
+ 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;
}
- 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);