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

Unified Diff: base/files/file_tracing.cc

Issue 2114993003: Access FileTracing::g_provider atomically to prevent data races (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: load and store Created 4 years, 5 months 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_tracing.cc
diff --git a/base/files/file_tracing.cc b/base/files/file_tracing.cc
index 6d11cbc746ed268a357e0d2ba08d463c501e5d96..d5ce12c7901bfb27c5b37bb64931f011b091743e 100644
--- a/base/files/file_tracing.cc
+++ b/base/files/file_tracing.cc
@@ -4,39 +4,54 @@
#include "base/files/file_tracing.h"
+#include "base/atomicops.h"
#include "base/files/file.h"
+using base::subtle::AtomicWord;
+
namespace base {
namespace {
-FileTracing::Provider* g_provider = nullptr;
+AtomicWord g_provider = reinterpret_cast<AtomicWord>(nullptr);
+}
+
+FileTracing::Provider* GetProvider() {
+ AtomicWord provider = base::subtle::NoBarrier_Load(&g_provider);
Alexander Potapenko 2016/07/09 10:32:04 You'll need Acquire_Load and Release_Store for get
groby-ooo-7-16 2016/07/13 20:05:04 In a nutshell: Follow Alexander's suggestion if yo
+ return reinterpret_cast<FileTracing::Provider*>(provider);
}
// static
bool FileTracing::IsCategoryEnabled() {
- return g_provider && g_provider->FileTracingCategoryIsEnabled();
+ FileTracing::Provider* provider = GetProvider();
+ return provider && provider->FileTracingCategoryIsEnabled();
}
// static
void FileTracing::SetProvider(FileTracing::Provider* provider) {
- g_provider = provider;
+ base::subtle::NoBarrier_Store(
+ &g_provider, reinterpret_cast<AtomicWord>(provider));
}
FileTracing::ScopedEnabler::ScopedEnabler() {
- if (g_provider)
- g_provider->FileTracingEnable(this);
+ FileTracing::Provider* provider = GetProvider();
+ if (provider)
+ provider->FileTracingEnable(this);
}
FileTracing::ScopedEnabler::~ScopedEnabler() {
- if (g_provider)
- g_provider->FileTracingDisable(this);
+ FileTracing::Provider* provider = GetProvider();
+ if (provider)
+ provider->FileTracingDisable(this);
}
FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {}
FileTracing::ScopedTrace::~ScopedTrace() {
- if (id_ && g_provider)
- g_provider->FileTracingEventEnd(name_, id_);
+ if (id_) {
+ FileTracing::Provider* provider = GetProvider();
+ if (provider)
+ provider->FileTracingEventEnd(name_, id_);
+ }
}
void FileTracing::ScopedTrace::Initialize(const char* name,
@@ -44,7 +59,7 @@ void FileTracing::ScopedTrace::Initialize(const char* name,
int64_t size) {
id_ = &file->trace_enabler_;
name_ = name;
- g_provider->FileTracingEventBegin(name_, id_, file->tracing_path_, size);
+ GetProvider()->FileTracingEventBegin(name_, id_, file->tracing_path_, size);
}
} // namespace base
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698