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

Unified Diff: base/metrics/statistics_recorder.h

Issue 2565893002: Fix TSAN race in access to StatisticsRecorder::lock_ (Closed)
Patch Set: nit Created 4 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 | « no previous file | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.h
diff --git a/base/metrics/statistics_recorder.h b/base/metrics/statistics_recorder.h
index b4dae8770996682e8d1cd7adb78806273c69ddf3..6deddae0109008c10afcff20a58bea52b1625ee7 100644
--- a/base/metrics/statistics_recorder.h
+++ b/base/metrics/statistics_recorder.h
@@ -25,11 +25,11 @@
#include "base/macros.h"
#include "base/metrics/histogram_base.h"
#include "base/strings/string_piece.h"
+#include "base/synchronization/lock.h"
namespace base {
class BucketRanges;
-class Lock;
class BASE_EXPORT StatisticsRecorder {
public:
@@ -230,8 +230,11 @@ class BASE_EXPORT StatisticsRecorder {
static CallbackMap* callbacks_;
static RangesMap* ranges_;
- // Lock protects access to above maps.
- static base::Lock* lock_;
+ // Lock protects access to above maps. This is a LazyInstance to avoid races
+ // when the above methods are used before Initialize(). Previously each method
+ // would do |if (!lock_) return;| which would race with
+ // |lock_ = new Lock;| in StatisticsRecorder(). http://crbug.com/672852.
+ static base::LazyInstance<base::Lock>::Leaky lock_;
DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
};
« 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