aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/iomgr/block_annotate.h8
-rw-r--r--src/core/lib/iomgr/exec_ctx.h2
-rw-r--r--src/core/lib/iomgr/iomgr.cc102
-rw-r--r--src/core/lib/iomgr/load_file.cc3
-rw-r--r--src/core/lib/surface/init.cc31
5 files changed, 81 insertions, 65 deletions
diff --git a/src/core/lib/iomgr/block_annotate.h b/src/core/lib/iomgr/block_annotate.h
index 55bde3eaac..e3d4368d17 100644
--- a/src/core/lib/iomgr/block_annotate.h
+++ b/src/core/lib/iomgr/block_annotate.h
@@ -46,6 +46,11 @@ void gpr_thd_end_blocking_region();
gpr_thd_end_blocking_region(); \
grpc_core::ExecCtx::Get()->InvalidateNow(); \
} while (0)
+#define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \
+ do { \
+ gpr_thd_end_blocking_region(); \
+ } while (0)
+
#else
#define GRPC_SCHEDULING_START_BLOCKING_REGION \
do { \
@@ -54,6 +59,9 @@ void gpr_thd_end_blocking_region();
do { \
grpc_core::ExecCtx::Get()->InvalidateNow(); \
} while (0)
+#define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \
+ do { \
+ } while (0)
#endif
#endif /* GRPC_CORE_LIB_IOMGR_BLOCK_ANNOTATE_H */
diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h
index 3a44d691b7..b04aab61fa 100644
--- a/src/core/lib/iomgr/exec_ctx.h
+++ b/src/core/lib/iomgr/exec_ctx.h
@@ -77,6 +77,7 @@ namespace grpc_core {
class ExecCtx {
public:
/** Default Constructor */
+
ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { Set(this); }
/** Parameterised Constructor */
@@ -84,7 +85,6 @@ class ExecCtx {
/** Destructor */
~ExecCtx() {
- GPR_ASSERT(Get() == this);
flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
Flush();
Set(last_exec_ctx_);
diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc
index 3bad17a54e..570d97443d 100644
--- a/src/core/lib/iomgr/iomgr.cc
+++ b/src/core/lib/iomgr/iomgr.cc
@@ -84,62 +84,66 @@ void grpc_iomgr_shutdown() {
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());
+ {
+ grpc_core::ExecCtx _local_exec_ctx(0);
+ 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);
- }
- 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;
- }
- 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_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");
+ 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;
}
- break;
}
}
}
- }
- gpr_mu_unlock(&g_mu);
+ gpr_mu_unlock(&g_mu);
- grpc_timer_list_shutdown();
- grpc_core::ExecCtx::Get()->Flush();
+ grpc_timer_list_shutdown();
+ }
/* ensure all threads have left g_mu */
gpr_mu_lock(&g_mu);
diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc
index 1afe6ba96d..4a05de1410 100644
--- a/src/core/lib/iomgr/load_file.cc
+++ b/src/core/lib/iomgr/load_file.cc
@@ -30,7 +30,6 @@
grpc_error* grpc_load_file(const char* filename, int add_null_terminator,
grpc_slice* output) {
- grpc_core::ExecCtx exec_ctx;
unsigned char* contents = nullptr;
size_t contents_size = 0;
grpc_slice result = grpc_empty_slice();
@@ -74,6 +73,6 @@ end:
GRPC_ERROR_UNREF(error);
error = error_out;
}
- GRPC_SCHEDULING_END_BLOCKING_REGION;
+ GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX;
return error;
}
diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc
index da641e1cf5..2d7a33e147 100644
--- a/src/core/lib/surface/init.cc
+++ b/src/core/lib/surface/init.cc
@@ -153,23 +153,28 @@ void grpc_shutdown(void) {
if (grpc_core::ExecCtx::Get()) {
grpc_core::ExecCtx::Get()->Flush();
}
- grpc_core::ExecCtx _local_exec_ctx(0);
gpr_mu_lock(&g_init_mu);
if (--g_initializations == 0) {
- grpc_executor_shutdown();
- grpc_timer_manager_set_threading(false); // shutdown timer_manager thread
- for (i = g_number_of_plugins; i >= 0; i--) {
- if (g_all_of_the_plugins[i].destroy != nullptr) {
- g_all_of_the_plugins[i].destroy();
+ {
+ {
+ grpc_core::ExecCtx _local_exec_ctx(0);
+ grpc_executor_shutdown();
+ grpc_timer_manager_set_threading(
+ false); // shutdown timer_manager thread
+ for (i = g_number_of_plugins; i >= 0; i--) {
+ if (g_all_of_the_plugins[i].destroy != nullptr) {
+ g_all_of_the_plugins[i].destroy();
+ }
+ }
+ grpc_mdctx_global_shutdown();
+ grpc_handshaker_factory_registry_shutdown();
}
+ grpc_iomgr_shutdown();
+ gpr_timers_global_destroy();
+ grpc_tracer_shutdown();
+ grpc_slice_intern_shutdown();
+ grpc_stats_shutdown();
}
- grpc_iomgr_shutdown();
- gpr_timers_global_destroy();
- grpc_tracer_shutdown();
- grpc_mdctx_global_shutdown();
- grpc_handshaker_factory_registry_shutdown();
- grpc_slice_intern_shutdown();
- grpc_stats_shutdown();
}
gpr_mu_unlock(&g_init_mu);
}