Merge pull request #20521 from mhaidrygoog/cleanup_tls

Initialize executor thread state globally and remove logic to destroy the thread state during shutdown
reviewable/pr20380/r4^2
Moiz Haidry 6 years ago committed by GitHub
commit a8b0ab8286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/core/lib/iomgr/executor.cc
  2. 3
      src/core/lib/iomgr/executor.h
  3. 1
      src/core/lib/surface/init.cc

@ -164,7 +164,6 @@ void Executor::SetThreading(bool threading) {
GPR_ASSERT(num_threads_ == 0);
gpr_atm_rel_store(&num_threads_, 1);
gpr_tls_init(&g_this_thread_state);
thd_state_ = static_cast<ThreadState*>(
gpr_zalloc(sizeof(ThreadState) * max_threads_));
@ -213,7 +212,6 @@ void Executor::SetThreading(bool threading) {
}
gpr_free(thd_state_);
gpr_tls_destroy(&g_this_thread_state);
// grpc_iomgr_shutdown_background_closure() will close all the registered
// fds in the background poller, and wait for all pending closures to
@ -265,14 +263,7 @@ void Executor::ThreadMain(void* arg) {
subtract_depth = RunClosures(ts->name, closures);
}
// We have an issue with Apple platforms where applying gpr_tls_set here
// leads to an EAGAIN error while performing a gpr_tls_get, so we are
// skipping this cleanup for Apple platforms. See PR #19978
// TODO(mhaidry) : Fix this by switching to using thread_local once we have
// support for it in Xcode (PR #20413)or whatever else it takes
#if !defined(__APPLE__)
gpr_tls_set(&g_this_thread_state, reinterpret_cast<intptr_t>(nullptr));
#endif // !__APPLE__
}
void Executor::Enqueue(grpc_closure* closure, grpc_error* error,
@ -494,4 +485,6 @@ void Executor::SetThreadingDefault(bool enable) {
executors[static_cast<size_t>(ExecutorType::DEFAULT)]->SetThreading(enable);
}
void grpc_executor_global_init() { gpr_tls_init(&g_this_thread_state); }
} // namespace grpc_core

@ -117,6 +117,9 @@ class Executor {
gpr_spinlock adding_thread_lock_;
};
// Global initializer for executor
void grpc_executor_global_init();
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */

@ -73,6 +73,7 @@ static void do_basic_init(void) {
g_shutting_down = false;
grpc_register_built_in_plugins();
grpc_cq_global_init();
grpc_core::grpc_executor_global_init();
gpr_time_init();
g_initializations = 0;
}

Loading…
Cancel
Save