aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/gprpp
diff options
context:
space:
mode:
authorGravatar kpayson64 <kpayson@google.com>2018-05-11 13:04:30 -0700
committerGravatar kpayson64 <kpayson@google.com>2018-05-11 13:04:30 -0700
commit40c93b6387571121979428035f2376e1e8f010d6 (patch)
tree67c07e81d6a36da7fc6472c102a3b28b2eac74fb /src/core/lib/gprpp
parentc934a2e25d403c21aeef9bacf37260bea9e0ca57 (diff)
Review changes
Diffstat (limited to 'src/core/lib/gprpp')
-rw-r--r--src/core/lib/gprpp/fork.cc58
-rw-r--r--src/core/lib/gprpp/fork.h2
2 files changed, 32 insertions, 28 deletions
diff --git a/src/core/lib/gprpp/fork.cc b/src/core/lib/gprpp/fork.cc
index ddc95f26eb..f6d9a87d2c 100644
--- a/src/core/lib/gprpp/fork.cc
+++ b/src/core/lib/gprpp/fork.cc
@@ -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,38 +157,37 @@ class ThreadState {
} // namespace
void Fork::GlobalInit() {
+ if (!overrideEnabled_) {
#ifdef GRPC_ENABLE_FORK_SUPPORT
- supportEnabled_ = true;
+ supportEnabled_ = true;
#else
- supportEnabled_ = false;
+ supportEnabled_ = false;
#endif
- bool env_var_set = false;
- char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");
- if (env != nullptr) {
- static const char* truthy[] = {"yes", "Yes", "YES", "true",
- "True", "TRUE", "1"};
- static const char* falsey[] = {"no", "No", "NO", "false",
- "False", "FALSE", "0"};
- for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
- if (0 == strcmp(env, truthy[i])) {
- supportEnabled_ = true;
- env_var_set = true;
- break;
- }
- }
- if (!env_var_set) {
- for (size_t i = 0; i < GPR_ARRAY_SIZE(falsey); i++) {
- if (0 == strcmp(env, falsey[i])) {
- supportEnabled_ = false;
+ bool env_var_set = false;
+ char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");
+ if (env != nullptr) {
+ static const char* truthy[] = {"yes", "Yes", "YES", "true",
+ "True", "TRUE", "1"};
+ static const char* falsey[] = {"no", "No", "NO", "false",
+ "False", "FALSE", "0"};
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
+ if (0 == strcmp(env, truthy[i])) {
+ supportEnabled_ = true;
env_var_set = true;
break;
}
}
+ if (!env_var_set) {
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(falsey); i++) {
+ if (0 == strcmp(env, falsey[i])) {
+ supportEnabled_ = false;
+ env_var_set = true;
+ break;
+ }
+ }
+ }
+ gpr_free(env);
}
- 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
diff --git a/src/core/lib/gprpp/fork.h b/src/core/lib/gprpp/fork.h
index 60ed74b1fb..123e22c4c6 100644
--- a/src/core/lib/gprpp/fork.h
+++ b/src/core/lib/gprpp/fork.h
@@ -71,7 +71,7 @@ class Fork {
static internal::ExecCtxState* execCtxState_;
static internal::ThreadState* threadState_;
static bool supportEnabled_;
- static int overrideEnabled_;
+ static bool overrideEnabled_;
};
} // namespace grpc_core