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

Unified Diff: base/metrics/sample_vector.cc

Issue 116983004: Change some operations touching counts_[] to be atomic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/sample_vector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/sample_vector.cc
===================================================================
--- base/metrics/sample_vector.cc (revision 242519)
+++ base/metrics/sample_vector.cc (working copy)
@@ -32,20 +32,20 @@
Count SampleVector::GetCount(Sample value) const {
size_t bucket_index = GetBucketIndex(value);
- return counts_[bucket_index];
+ return subtle::NoBarrier_Load(&counts_[bucket_index]);
}
Count SampleVector::TotalCount() const {
Count count = 0;
for (size_t i = 0; i < counts_.size(); i++) {
- count += counts_[i];
+ count += subtle::NoBarrier_Load(&counts_[i]);
}
return count;
}
Count SampleVector::GetCountAtIndex(size_t bucket_index) const {
DCHECK(bucket_index < counts_.size());
- return counts_[bucket_index];
+ return subtle::NoBarrier_Load(&counts_[bucket_index]);
}
scoped_ptr<SampleCountIterator> SampleVector::Iterator() const {
@@ -66,7 +66,10 @@
if (min == bucket_ranges_->range(index) &&
max == bucket_ranges_->range(index + 1)) {
// Sample matches this bucket!
- counts_[index] += (op == HistogramSamples::ADD) ? count : -count;
+ HistogramBase::Count old_counts =
+ subtle::NoBarrier_Load(&counts_[index]);
+ subtle::NoBarrier_Store(&counts_[index],
+ old_counts + ((op == HistogramSamples::ADD) ? count : -count));
iter->Next();
} else if (min > bucket_ranges_->range(index)) {
// Sample is larger than current bucket range. Try next.
@@ -138,7 +141,7 @@
if (max != NULL)
*max = bucket_ranges_->range(index_ + 1);
if (count != NULL)
- *count = (*counts_)[index_];
+ *count = subtle::NoBarrier_Load(&(*counts_)[index_]);
}
bool SampleVectorIterator::GetBucketIndex(size_t* index) const {
@@ -153,7 +156,7 @@
return;
while (index_ < counts_->size()) {
- if ((*counts_)[index_] != 0)
+ if (subtle::NoBarrier_Load(&(*counts_)[index_]) != 0)
return;
index_++;
}
« no previous file with comments | « base/metrics/sample_vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698