|
|
|
@ -56,7 +56,7 @@ class ExecCtxState { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void IncExecCtxCount() { |
|
|
|
|
intptr_t count = static_cast<intptr_t>(gpr_atm_no_barrier_load(&count_)); |
|
|
|
|
gpr_atm count = gpr_atm_no_barrier_load(&count_); |
|
|
|
|
while (true) { |
|
|
|
|
if (count <= BLOCKED(1)) { |
|
|
|
|
// This only occurs if we are trying to fork. Wait until the fork()
|
|
|
|
@ -80,7 +80,9 @@ class ExecCtxState { |
|
|
|
|
bool BlockExecCtx() { |
|
|
|
|
// Assumes there is an active ExecCtx when this function is called
|
|
|
|
|
if (gpr_atm_no_barrier_cas(&count_, UNBLOCKED(1), BLOCKED(1))) { |
|
|
|
|
gpr_mu_lock(&mu_); |
|
|
|
|
fork_complete_ = false; |
|
|
|
|
gpr_mu_unlock(&mu_); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
@ -155,6 +157,7 @@ class ThreadState { |
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void Fork::GlobalInit() { |
|
|
|
|
if (!overrideEnabled_) { |
|
|
|
|
#ifdef GRPC_ENABLE_FORK_SUPPORT |
|
|
|
|
supportEnabled_ = true; |
|
|
|
|
#else |
|
|
|
@ -185,8 +188,6 @@ void Fork::GlobalInit() { |
|
|
|
|
} |
|
|
|
|
gpr_free(env); |
|
|
|
|
} |
|
|
|
|
if (overrideEnabled_ != -1) { |
|
|
|
|
supportEnabled_ = (overrideEnabled_ == 1); |
|
|
|
|
} |
|
|
|
|
if (supportEnabled_) { |
|
|
|
|
execCtxState_ = grpc_core::New<internal::ExecCtxState>(); |
|
|
|
@ -204,7 +205,10 @@ void Fork::GlobalShutdown() { |
|
|
|
|
bool Fork::Enabled() { return supportEnabled_; } |
|
|
|
|
|
|
|
|
|
// Testing Only
|
|
|
|
|
void Fork::Enable(bool enable) { overrideEnabled_ = enable ? 1 : 0; } |
|
|
|
|
void Fork::Enable(bool enable) { |
|
|
|
|
overrideEnabled_ = true; |
|
|
|
|
supportEnabled_ = enable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Fork::IncExecCtxCount() { |
|
|
|
|
if (supportEnabled_) { |
|
|
|
@ -251,6 +255,6 @@ void Fork::AwaitThreads() { |
|
|
|
|
internal::ExecCtxState* Fork::execCtxState_ = nullptr; |
|
|
|
|
internal::ThreadState* Fork::threadState_ = nullptr; |
|
|
|
|
bool Fork::supportEnabled_ = false; |
|
|
|
|
int Fork::overrideEnabled_ = -1; |
|
|
|
|
bool Fork::overrideEnabled_ = false; |
|
|
|
|
|
|
|
|
|
} // namespace grpc_core
|
|
|
|
|