diff options
Diffstat (limited to 'chromium/v8/src/heap/safepoint.cc')
-rw-r--r-- | chromium/v8/src/heap/safepoint.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/chromium/v8/src/heap/safepoint.cc b/chromium/v8/src/heap/safepoint.cc index e6ccf642c09..3012413f48c 100644 --- a/chromium/v8/src/heap/safepoint.cc +++ b/chromium/v8/src/heap/safepoint.cc @@ -13,13 +13,16 @@ namespace v8 { namespace internal { GlobalSafepoint::GlobalSafepoint(Heap* heap) - : heap_(heap), local_heaps_head_(nullptr), is_active_(false) {} + : heap_(heap), local_heaps_head_(nullptr), active_safepoint_scopes_(0) {} -void GlobalSafepoint::Start() { StopThreads(); } +void GlobalSafepoint::Start() { EnterSafepointScope(); } -void GlobalSafepoint::End() { ResumeThreads(); } +void GlobalSafepoint::End() { LeaveSafepointScope(); } -void GlobalSafepoint::StopThreads() { +void GlobalSafepoint::EnterSafepointScope() { + if (!FLAG_local_heaps) return; + + if (++active_safepoint_scopes_ > 1) return; local_heaps_mutex_.Lock(); barrier_.Arm(); @@ -37,12 +40,13 @@ void GlobalSafepoint::StopThreads() { current->state_change_.Wait(¤t->state_mutex_); } } - - is_active_ = true; } -void GlobalSafepoint::ResumeThreads() { - is_active_ = false; +void GlobalSafepoint::LeaveSafepointScope() { + if (!FLAG_local_heaps) return; + + DCHECK_GT(active_safepoint_scopes_, 0); + if (--active_safepoint_scopes_ > 0) return; for (LocalHeap* current = local_heaps_head_; current; current = current->next_) { @@ -90,12 +94,10 @@ void GlobalSafepoint::Barrier::Wait() { } SafepointScope::SafepointScope(Heap* heap) : safepoint_(heap->safepoint()) { - if (FLAG_local_heaps) safepoint_->StopThreads(); + safepoint_->EnterSafepointScope(); } -SafepointScope::~SafepointScope() { - if (FLAG_local_heaps) safepoint_->ResumeThreads(); -} +SafepointScope::~SafepointScope() { safepoint_->LeaveSafepointScope(); } void GlobalSafepoint::AddLocalHeap(LocalHeap* local_heap) { base::MutexGuard guard(&local_heaps_mutex_); |