OLD | NEW |
---|---|
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; | |
danakj
2016/07/07 22:40:36
nit: you could put this in the method that uses it
Dan Beam
2016/07/07 23:13:48
Done.
| |
11 | |
9 namespace base { | 12 namespace base { |
10 | 13 |
11 namespace { | 14 namespace { |
12 FileTracing::Provider* g_provider = nullptr; | 15 FileTracing::Provider* g_provider = nullptr; |
13 } | 16 } |
14 | 17 |
15 // static | 18 // static |
16 bool FileTracing::IsCategoryEnabled() { | 19 bool FileTracing::IsCategoryEnabled() { |
17 return g_provider && g_provider->FileTracingCategoryIsEnabled(); | 20 return g_provider && g_provider->FileTracingCategoryIsEnabled(); |
18 } | 21 } |
19 | 22 |
20 // static | 23 // static |
21 void FileTracing::SetProvider(FileTracing::Provider* provider) { | 24 void FileTracing::SetProvider(FileTracing::Provider* provider) { |
22 g_provider = provider; | 25 base::subtle::NoBarrier_Store(reinterpret_cast<AtomicWord*>(&g_provider), |
danakj
2016/07/07 22:40:36
I think the way most people do this would be with
Dan Beam
2016/07/07 23:13:48
g_provider should only be set once. ever. i can ve
danakj
2016/07/07 23:21:04
Ah, so it's just threads are reading null.. readin
| |
26 reinterpret_cast<AtomicWord>(provider)); | |
23 } | 27 } |
24 | 28 |
25 FileTracing::ScopedEnabler::ScopedEnabler() { | 29 FileTracing::ScopedEnabler::ScopedEnabler() { |
26 if (g_provider) | 30 if (g_provider) |
27 g_provider->FileTracingEnable(this); | 31 g_provider->FileTracingEnable(this); |
28 } | 32 } |
29 | 33 |
30 FileTracing::ScopedEnabler::~ScopedEnabler() { | 34 FileTracing::ScopedEnabler::~ScopedEnabler() { |
31 if (g_provider) | 35 if (g_provider) |
32 g_provider->FileTracingDisable(this); | 36 g_provider->FileTracingDisable(this); |
33 } | 37 } |
34 | 38 |
35 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {} | 39 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {} |
36 | 40 |
37 FileTracing::ScopedTrace::~ScopedTrace() { | 41 FileTracing::ScopedTrace::~ScopedTrace() { |
38 if (id_ && g_provider) | 42 if (id_ && g_provider) |
39 g_provider->FileTracingEventEnd(name_, id_); | 43 g_provider->FileTracingEventEnd(name_, id_); |
40 } | 44 } |
41 | 45 |
42 void FileTracing::ScopedTrace::Initialize(const char* name, | 46 void FileTracing::ScopedTrace::Initialize(const char* name, |
43 File* file, | 47 File* file, |
44 int64_t size) { | 48 int64_t size) { |
45 id_ = &file->trace_enabler_; | 49 id_ = &file->trace_enabler_; |
46 name_ = name; | 50 name_ = name; |
47 g_provider->FileTracingEventBegin(name_, id_, file->tracing_path_, size); | 51 g_provider->FileTracingEventBegin(name_, id_, file->tracing_path_, size); |
48 } | 52 } |
49 | 53 |
50 } // namespace base | 54 } // namespace base |
OLD | NEW |