Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index 3154f72ac3d303d7c423c3eded8f2cfd6f993606..3ea27298024334d7c15c16058d99d8d9160bbffb 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -2549,7 +2549,6 @@ Isolate::~Isolate() { |
delete logger_; |
logger_ = NULL; |
- delete counters_; |
counters_ = NULL; |
delete handle_scope_implementer_; |
@@ -2635,14 +2634,22 @@ bool Isolate::PropagatePendingExceptionToExternalTryCatch() { |
return true; |
} |
+static base::LazyMutex initialize_counters_mutex = LAZY_MUTEX_INITIALIZER; |
+ |
+bool Isolate::InitializeCounters() { |
+ if (counters_ != nullptr) return false; |
Clemens Hammacher
2017/06/02 13:08:49
This pattern is not safe in general. A thread obse
kschimpf
2017/06/02 15:01:02
I was probably too concerned about this, since the
kschimpf
2017/06/02 17:06:27
Fixed in cl https://codereview.chromium.org/291995
|
+ base::LockGuard<base::Mutex> guard(initialize_counters_mutex.Pointer()); |
+ if (counters_ != nullptr) return false; |
+ counters_shared_ = std::make_shared<Counters>(this); |
+ counters_ = counters_shared_.get(); |
+ return true; |
+} |
void Isolate::InitializeLoggingAndCounters() { |
if (logger_ == NULL) { |
logger_ = new Logger(this); |
} |
- if (counters_ == NULL) { |
- counters_ = new Counters(this); |
- } |
+ InitializeCounters(); |
} |