Chromium Code Reviews| Index: base/metrics/histogram_snapshot_manager.cc |
| diff --git a/base/metrics/histogram_snapshot_manager.cc b/base/metrics/histogram_snapshot_manager.cc |
| index 32702d8b3eb94a8800b4fe4f45f487ee4a26df74..42a2d7455490b4c593d94727c4f681feab6d9f12 100644 |
| --- a/base/metrics/histogram_snapshot_manager.cc |
| +++ b/base/metrics/histogram_snapshot_manager.cc |
| @@ -14,10 +14,29 @@ |
| namespace base { |
| +namespace { |
| + |
| +// A simple object to set an "active" flag and clear it upon destruction. It is |
| +// an error if the flag is already set. |
| +class MakeActive { |
| + public: |
| + MakeActive(std::atomic<bool>* is_active) : is_active_(is_active) { |
| + bool was_active = is_active_->exchange(true, std::memory_order_relaxed); |
| + CHECK(!was_active); |
| + } |
| + ~MakeActive() { is_active_->store(false, std::memory_order_relaxed); } |
| + |
| + private: |
| + std::atomic<bool>* is_active_; |
|
Alexei Svitkine (slow)
2017/05/08 18:51:09
Nit: DISALLOW_COPY_AND_ASSIGN()
bcwhite
2017/05/08 20:06:49
Done.
|
| +}; |
| + |
| +} // namespace |
| + |
| HistogramSnapshotManager::HistogramSnapshotManager( |
| HistogramFlattener* histogram_flattener) |
| : histogram_flattener_(histogram_flattener) { |
| DCHECK(histogram_flattener_); |
| + is_active_.store(false, std::memory_order_relaxed); |
| } |
| HistogramSnapshotManager::~HistogramSnapshotManager() { |
| @@ -35,9 +54,13 @@ void HistogramSnapshotManager::PrepareFinalDelta( |
| void HistogramSnapshotManager::PrepareSamples( |
| const HistogramBase* histogram, |
| std::unique_ptr<HistogramSamples> samples) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(histogram_flattener_); |
| + // Ensure that there is no concurrent access going on while accessing the |
| + // set of known histograms. The flag will be reset when this object goes |
| + // out of scope. |
| + MakeActive make_active(&is_active_); |
| + |
| // Get information known about this histogram. If it did not previously |
| // exist, one will be created and initialized. |
| SampleInfo* sample_info = &known_histograms_[histogram->name_hash()]; |