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

Side by Side Diff: base/metrics/persistent_histogram_allocator.cc

Issue 1872713002: Remove unnecessary lock that causes reentry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added comment as to why Import is done before lock Created 4 years, 8 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 | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/metrics/persistent_histogram_allocator.h" 5 #include "base/metrics/persistent_histogram_allocator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 568
569 void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() { 569 void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() {
570 // Skip the import if it's the histogram that was last created. Should a 570 // Skip the import if it's the histogram that was last created. Should a
571 // race condition cause the "last created" to be overwritten before it 571 // race condition cause the "last created" to be overwritten before it
572 // is recognized here then the histogram will be created and be ignored 572 // is recognized here then the histogram will be created and be ignored
573 // when it is detected as a duplicate by the statistics-recorder. This 573 // when it is detected as a duplicate by the statistics-recorder. This
574 // simple check reduces the time of creating persistent histograms by 574 // simple check reduces the time of creating persistent histograms by
575 // about 40%. 575 // about 40%.
576 Reference record_to_ignore = last_created(); 576 Reference record_to_ignore = last_created();
577 577
578 // There is no lock on this because it's expected to be called only by 578 // There is no lock on this because the iterator is lock-free while still
579 // the StatisticsRecorder which has its own lock. 579 // guaranteed to only return each entry only once. The StatisticsRecorder
580 // has its own lock so the Register operation is safe.
580 while (true) { 581 while (true) {
581 std::unique_ptr<HistogramBase> histogram = 582 std::unique_ptr<HistogramBase> histogram =
582 import_iterator_.GetNextWithIgnore(record_to_ignore); 583 import_iterator_.GetNextWithIgnore(record_to_ignore);
583 if (!histogram) 584 if (!histogram)
584 break; 585 break;
585 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); 586 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release());
586 } 587 }
587 } 588 }
588 589
589 } // namespace base 590 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698