Skip to content

Commit

Permalink
OpenCensus: Fix data race (grpc#31255)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashykt authored Oct 6, 2022
1 parent c802adf commit 0469b1e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/cpp/ext/filters/census/grpc_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <limits.h>

#include <atomic>

#include "absl/base/attributes.h"
#include "opencensus/tags/tag_key.h"
#include "opencensus/trace/span.h"
Expand Down Expand Up @@ -161,8 +163,8 @@ ABSL_CONST_INIT const absl::string_view kRpcServerServerLatencyMeasureName =
ABSL_CONST_INIT const absl::string_view kRpcServerStartedRpcsMeasureName =
"grpc.io/server/started_rpcs";

bool g_open_census_stats_enabled = true;
bool g_open_census_tracing_enabled = true;
std::atomic<bool> g_open_census_stats_enabled(true);
std::atomic<bool> g_open_census_tracing_enabled(true);

void EnableOpenCensusStats(bool enable) {
g_open_census_stats_enabled = enable;
Expand All @@ -172,8 +174,12 @@ void EnableOpenCensusTracing(bool enable) {
g_open_census_tracing_enabled = enable;
}

bool OpenCensusStatsEnabled() { return g_open_census_stats_enabled; }
bool OpenCensusStatsEnabled() {
return g_open_census_stats_enabled.load(std::memory_order_relaxed);
}

bool OpenCensusTracingEnabled() { return g_open_census_tracing_enabled; }
bool OpenCensusTracingEnabled() {
return g_open_census_tracing_enabled.load(std::memory_order_relaxed);
}

} // namespace grpc

0 comments on commit 0469b1e

Please sign in to comment.