Merge pull request #15825 from kpayson64/exec_ctx_check_bugfix

Don't count internal threads against ExecCtx count
pull/15850/head
kpayson64 7 years ago committed by GitHub
commit 8c6bea1938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/lib/iomgr/exec_ctx.h
  2. 2
      src/core/lib/iomgr/executor.cc
  3. 2
      src/core/lib/iomgr/timer_manager.cc

@ -45,6 +45,9 @@ typedef struct grpc_combiner grpc_combiner;
/* The exec_ctx's thread is (potentially) owned by a call or channel: care /* The exec_ctx's thread is (potentially) owned by a call or channel: care
should be given to not delete said call/channel from this exec_ctx */ should be given to not delete said call/channel from this exec_ctx */
#define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2
/* This exec ctx was initialized by an internal thread, and should not
be counted by fork handlers */
#define GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD 4
extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx;
@ -93,7 +96,9 @@ class ExecCtx {
/** Parameterised Constructor */ /** Parameterised Constructor */
ExecCtx(uintptr_t fl) : flags_(fl) { ExecCtx(uintptr_t fl) : flags_(fl) {
if (!(GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD & flags_)) {
grpc_core::Fork::IncExecCtxCount(); grpc_core::Fork::IncExecCtxCount();
}
Set(this); Set(this);
} }
@ -102,8 +107,10 @@ class ExecCtx {
flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
Flush(); Flush();
Set(last_exec_ctx_); Set(last_exec_ctx_);
if (!(GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD & flags_)) {
grpc_core::Fork::DecExecCtxCount(); grpc_core::Fork::DecExecCtxCount();
} }
}
/** Disallow copy and assignment operators */ /** Disallow copy and assignment operators */
ExecCtx(const ExecCtx&) = delete; ExecCtx(const ExecCtx&) = delete;

@ -145,7 +145,7 @@ static void executor_thread(void* arg) {
thread_state* ts = static_cast<thread_state*>(arg); thread_state* ts = static_cast<thread_state*>(arg);
gpr_tls_set(&g_this_thread_state, (intptr_t)ts); gpr_tls_set(&g_this_thread_state, (intptr_t)ts);
grpc_core::ExecCtx exec_ctx(0); grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD);
size_t subtract_depth = 0; size_t subtract_depth = 0;
for (;;) { for (;;) {

@ -265,7 +265,7 @@ static void timer_thread_cleanup(completed_thread* ct) {
static void timer_thread(void* completed_thread_ptr) { static void timer_thread(void* completed_thread_ptr) {
// this threads exec_ctx: we try to run things through to completion here // this threads exec_ctx: we try to run things through to completion here
// since it's easy to spin up new threads // since it's easy to spin up new threads
grpc_core::ExecCtx exec_ctx(0); grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_INTERNAL_THREAD);
timer_main_loop(); timer_main_loop();
timer_thread_cleanup(static_cast<completed_thread*>(completed_thread_ptr)); timer_thread_cleanup(static_cast<completed_thread*>(completed_thread_ptr));

Loading…
Cancel
Save