Index: base/tracked_objects.cc |
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc |
index 72049e4b66a49341ce23751455f98472c9fa1f2a..5fa3cd3fda542a60341c4150fd7efccf2a0b862c 100644 |
--- a/base/tracked_objects.cc |
+++ b/base/tracked_objects.cc |
@@ -7,6 +7,7 @@ |
#include <limits.h> |
#include <stdlib.h> |
+#include "base/atomicops.h" |
#include "base/base_switches.h" |
#include "base/command_line.h" |
#include "base/compiler_specific.h" |
@@ -54,25 +55,26 @@ const ThreadData::Status kInitialStartupState = |
static const bool kAllowAlternateTimeSourceHandling = true; |
inline bool IsProfilerTimingEnabled() { |
- static enum { |
+ enum { |
UNDEFINED_TIMING, |
ENABLED_TIMING, |
DISABLED_TIMING, |
- } timing_enabled = UNDEFINED_TIMING; |
- // This initialization is not thread-safe, so the value of |timing_enabled| |
- // can be computed multiple times. This is not an issue, as the computed value |
- // will always be the same, and is side-effect free, while needing to use a |
- // lock or a memory barrier would be more costly. |
- if (timing_enabled == UNDEFINED_TIMING) { |
+ }; |
+ static base::subtle::Atomic32 timing_enabled = UNDEFINED_TIMING; |
+ base::subtle::Atomic32 current_timing_enabled = |
+ base::subtle::NoBarrier_Load(&timing_enabled); |
+ if (current_timing_enabled == UNDEFINED_TIMING) { |
if (!CommandLine::InitializedForCurrentProcess()) |
return true; |
- timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
- switches::kProfilerTiming) == |
- switches::kProfilerTimingDisabledValue) |
- ? DISABLED_TIMING |
- : ENABLED_TIMING; |
+ current_timing_enabled = |
+ (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kProfilerTiming) == |
+ switches::kProfilerTimingDisabledValue) |
+ ? DISABLED_TIMING |
+ : ENABLED_TIMING; |
+ base::subtle::Release_Store(&timing_enabled, current_timing_enabled); |
Alexander Potapenko
2013/12/12 09:43:14
This can be a NoBarrier_Store, since you're not ac
qsr
2013/12/12 10:06:20
Done.
|
} |
- return timing_enabled == ENABLED_TIMING; |
+ return current_timing_enabled == ENABLED_TIMING; |
} |
} // namespace |