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

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: silly quirks are silly 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..df859a454de58318f1ce977442f69cf2ebbc39a1 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;
+}
+
+FileTracing::Provider* GetProvider() {
+ AtomicWord provider = base::subtle::Acquire_Load(&g_provider);
+ 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::Release_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