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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_tracing.h" 5 #include "base/files/file_tracing.h"
6 6
7 #include "base/atomicops.h"
7 #include "base/files/file.h" 8 #include "base/files/file.h"
8 9
10 using base::subtle::AtomicWord;
11
9 namespace base { 12 namespace base {
10 13
11 namespace { 14 namespace {
12 FileTracing::Provider* g_provider = nullptr; 15 AtomicWord g_provider;
16 }
17
18 FileTracing::Provider* GetProvider() {
19 AtomicWord provider = base::subtle::Acquire_Load(&g_provider);
20 return reinterpret_cast<FileTracing::Provider*>(provider);
13 } 21 }
14 22
15 // static 23 // static
16 bool FileTracing::IsCategoryEnabled() { 24 bool FileTracing::IsCategoryEnabled() {
17 return g_provider && g_provider->FileTracingCategoryIsEnabled(); 25 FileTracing::Provider* provider = GetProvider();
26 return provider && provider->FileTracingCategoryIsEnabled();
18 } 27 }
19 28
20 // static 29 // static
21 void FileTracing::SetProvider(FileTracing::Provider* provider) { 30 void FileTracing::SetProvider(FileTracing::Provider* provider) {
22 g_provider = provider; 31 base::subtle::Release_Store(&g_provider,
32 reinterpret_cast<AtomicWord>(provider));
23 } 33 }
24 34
25 FileTracing::ScopedEnabler::ScopedEnabler() { 35 FileTracing::ScopedEnabler::ScopedEnabler() {
26 if (g_provider) 36 FileTracing::Provider* provider = GetProvider();
27 g_provider->FileTracingEnable(this); 37 if (provider)
38 provider->FileTracingEnable(this);
28 } 39 }
29 40
30 FileTracing::ScopedEnabler::~ScopedEnabler() { 41 FileTracing::ScopedEnabler::~ScopedEnabler() {
31 if (g_provider) 42 FileTracing::Provider* provider = GetProvider();
32 g_provider->FileTracingDisable(this); 43 if (provider)
44 provider->FileTracingDisable(this);
33 } 45 }
34 46
35 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {} 47 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {}
36 48
37 FileTracing::ScopedTrace::~ScopedTrace() { 49 FileTracing::ScopedTrace::~ScopedTrace() {
38 if (id_ && g_provider) 50 if (id_) {
39 g_provider->FileTracingEventEnd(name_, id_); 51 FileTracing::Provider* provider = GetProvider();
52 if (provider)
53 provider->FileTracingEventEnd(name_, id_);
54 }
40 } 55 }
41 56
42 void FileTracing::ScopedTrace::Initialize(const char* name, 57 void FileTracing::ScopedTrace::Initialize(const char* name,
43 File* file, 58 File* file,
44 int64_t size) { 59 int64_t size) {
45 id_ = &file->trace_enabler_; 60 id_ = &file->trace_enabler_;
46 name_ = name; 61 name_ = name;
47 g_provider->FileTracingEventBegin(name_, id_, file->tracing_path_, size); 62 GetProvider()->FileTracingEventBegin(name_, id_, file->tracing_path_, size);
48 } 63 }
49 64
50 } // namespace base 65 } // namespace base
OLDNEW
« 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