Index: runtime/vm/thread_registry.h |
diff --git a/runtime/vm/thread_registry.h b/runtime/vm/thread_registry.h |
index efe81bdcfa69ca8540760424d8a289bca8943275..c758a89e7f04ca67f8616f3cde720a24d229f9a8 100644 |
--- a/runtime/vm/thread_registry.h |
+++ b/runtime/vm/thread_registry.h |
@@ -27,12 +27,16 @@ class ThreadRegistry { |
// Bring all threads in this isolate to a safepoint. The caller is |
// expected to be implicitly at a safepoint. The threads will wait |
// until ResumeAllThreads is called. First participates in any |
- // already pending rendezvous requested by another thread. Any |
+ // already pending rendezvous requested by another thread. |
+ // |
+ // Returns an identifier of this rendezvous, which can be passed to |
+ // Thread::EnterIsolateAsHelper to allow the thread free passage in/out |
+ // of the isolate while this rendezvous is in progress. Otherwise, any |
// thread that tries to enter this isolate during rendezvous will |
// wait in RestoreStateTo. Nesting is not supported: the caller must |
// call ResumeAllThreads before making further calls to |
// SafepointThreads. |
- void SafepointThreads(); |
+ SafepointId SafepointThreads(); |
// Unblocks all threads participating in the rendezvous that was organized |
// by a prior call to SafepointThreads. |
@@ -49,7 +53,7 @@ class ThreadRegistry { |
bool RestoreStateTo(Thread* thread, Thread::State* state) { |
MonitorLocker ml(monitor_); |
// Wait for any rendezvous in progress. |
- while (in_rendezvous_) { |
+ while (IsParticipant(thread)) { |
ml.Wait(Monitor::kNoTimeout); |
} |
Entry* entry = FindEntry(thread); |
@@ -88,8 +92,8 @@ class ThreadRegistry { |
ASSERT(entry->scheduled); |
entry->scheduled = false; |
entry->state = state; |
- if (in_rendezvous_) { |
- // Don't wait for this thread. |
+ if (IsParticipant(thread)) { |
+ // Update count (don't wait for this thread when resuming). |
ASSERT(remaining_ > 0); |
if (--remaining_ == 0) { |
ml.NotifyAll(); |
@@ -158,9 +162,11 @@ class ThreadRegistry { |
// Note: Lock should be taken before this function is called. |
void CheckSafepointLocked(); |
- // Returns the number threads that are scheduled on this isolate. |
- // Note: Lock should be taken before this function is called. |
- intptr_t CountScheduledLocked(); |
+ // Returns true if there is a rendezvous in progress and the given thread |
+ // is/will be a participant of it. |
+ bool IsParticipant(Thread* thread) { |
+ return in_rendezvous_ && (thread->pass_safepoint_ != round_); |
+ } |
Monitor* monitor_; // All access is synchronized through this monitor. |
MallocGrowableArray<Entry> entries_; |