Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2764)

Unified Diff: base/tracked_objects.cc

Issue 111873003: Use Atomic in IsProfilerTimingEnabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/valgrind/tsan_v2/suppressions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | tools/valgrind/tsan_v2/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698