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

Side by Side Diff: net/disk_cache/stats_histogram.cc

Issue 6780035: Use lock-free lazy initialization for static histogram references (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/stats_histogram.h ('k') | net/socket/client_socket_pool_histograms.h » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/disk_cache/stats_histogram.h" 5 #include "net/disk_cache/stats_histogram.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/disk_cache/stats.h" 8 #include "net/disk_cache/stats.h"
9 9
10 namespace disk_cache { 10 namespace disk_cache {
11 11
12 using base::Histogram; 12 using base::Histogram;
13 using base::StatisticsRecorder; 13 using base::StatisticsRecorder;
14 14
15 // Static. 15 // Static.
16 const Stats* StatsHistogram::stats_ = NULL; 16 const Stats* StatsHistogram::stats_ = NULL;
17 17
18 StatsHistogram::~StatsHistogram() { 18 StatsHistogram::~StatsHistogram() {
19 // Only cleanup what we set. 19 // Only cleanup what we set.
20 if (init_) 20 if (init_)
21 stats_ = NULL; 21 stats_ = NULL;
22 } 22 }
23 23
24 scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet( 24 StatsHistogram* StatsHistogram::StatsHistogramFactoryGet(
25 const std::string& name) { 25 const std::string& name) {
26 scoped_refptr<Histogram> histogram(NULL); 26 Histogram* histogram(NULL);
27 27
28 Sample minimum = 1; 28 Sample minimum = 1;
29 Sample maximum = disk_cache::Stats::kDataSizesLength - 1; 29 Sample maximum = disk_cache::Stats::kDataSizesLength - 1;
30 size_t bucket_count = disk_cache::Stats::kDataSizesLength; 30 size_t bucket_count = disk_cache::Stats::kDataSizesLength;
31 31
32 if (StatisticsRecorder::FindHistogram(name, &histogram)) { 32 if (StatisticsRecorder::FindHistogram(name, &histogram)) {
33 DCHECK(histogram.get() != NULL); 33 DCHECK(histogram != NULL);
34 } else { 34 } else {
35 StatsHistogram* stats_histogram = new StatsHistogram(name, minimum, maximum, 35 // To avoid racy destruction at shutdown, the following will be leaked.
36 bucket_count); 36 StatsHistogram* stats_histogram =
37 new StatsHistogram(name, minimum, maximum, bucket_count);
37 stats_histogram->InitializeBucketRange(); 38 stats_histogram->InitializeBucketRange();
38 histogram = stats_histogram; 39 stats_histogram->SetFlags(kUmaTargetedHistogramFlag);
39 histogram->SetFlags(kUmaTargetedHistogramFlag); 40 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(stats_histogram);
40 StatisticsRecorder::RegisterOrDiscardDuplicate(&histogram);
41 } 41 }
42 42
43 DCHECK(HISTOGRAM == histogram->histogram_type()); 43 DCHECK(HISTOGRAM == histogram->histogram_type());
44 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); 44 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
45 45
46 // We're preparing for an otherwise unsafe upcast by ensuring we have the 46 // We're preparing for an otherwise unsafe upcast by ensuring we have the
47 // proper class type. 47 // proper class type.
48 Histogram* temp_histogram = histogram.get(); 48 StatsHistogram* return_histogram = static_cast<StatsHistogram*>(histogram);
49 StatsHistogram* temp_stats_histogram =
50 static_cast<StatsHistogram*>(temp_histogram);
51 // Validate upcast by seeing that we're probably providing the checksum. 49 // Validate upcast by seeing that we're probably providing the checksum.
52 CHECK_EQ(temp_stats_histogram->StatsHistogram::CalculateRangeChecksum(), 50 CHECK_EQ(return_histogram->StatsHistogram::CalculateRangeChecksum(),
53 temp_stats_histogram->CalculateRangeChecksum()); 51 return_histogram->CalculateRangeChecksum());
54 scoped_refptr<StatsHistogram> return_histogram(temp_stats_histogram);
55 return return_histogram; 52 return return_histogram;
56 } 53 }
57 54
58 bool StatsHistogram::Init(const Stats* stats) { 55 bool StatsHistogram::Init(const Stats* stats) {
59 DCHECK(stats); 56 DCHECK(stats);
60 if (stats_) 57 if (stats_)
61 return false; 58 return false;
62 59
63 // We support statistics report for only one cache. 60 // We support statistics report for only one cache.
64 init_ = true; 61 init_ = true;
(...skipping 27 matching lines...) Expand all
92 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies. 89 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies.
93 } 90 }
94 91
95 uint32 StatsHistogram::CalculateRangeChecksum() const { 92 uint32 StatsHistogram::CalculateRangeChecksum() const {
96 // We don't calculate checksums, so at least establish a unique constant. 93 // We don't calculate checksums, so at least establish a unique constant.
97 const uint32 kStatsHistogramChecksum = 0x0cecce; 94 const uint32 kStatsHistogramChecksum = 0x0cecce;
98 return kStatsHistogramChecksum; 95 return kStatsHistogramChecksum;
99 } 96 }
100 97
101 } // namespace disk_cache 98 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/stats_histogram.h ('k') | net/socket/client_socket_pool_histograms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698