OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/thread_registry.h" | 5 #include "vm/thread_registry.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/lockers.h" | 8 #include "vm/lockers.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 void ThreadRegistry::SafepointThreads() { | 12 void ThreadRegistry::SafepointThreads() { |
13 MonitorLocker ml(monitor_); | 13 MonitorLocker ml(monitor_); |
14 // First wait for any older rounds that are still in progress. | 14 // First wait for any older rounds that are still in progress. |
15 while (in_rendezvous_) { | 15 while (in_rendezvous_) { |
16 // Assert we are not the organizer trying to nest calls to SafepointThreads. | 16 // Assert we are not the organizer trying to nest calls to SafepointThreads. |
17 ASSERT(remaining_ > 0); | 17 ASSERT(remaining_ > 0); |
18 CheckSafepointLocked(); | 18 CheckSafepointLocked(); |
19 } | 19 } |
20 // Start a new round. | 20 // Start a new round. |
21 in_rendezvous_ = true; | 21 in_rendezvous_ = true; |
22 ++round_; // Overflows after 240+ years @ 10^9 safepoints per second. | 22 ++round_; // Overflows after 240+ years @ 10^9 safepoints per second. |
23 remaining_ = CountScheduledLocked(); | 23 remaining_ = CountScheduledLocked(); |
24 Isolate* isolate = Isolate::Current(); | 24 Isolate* isolate = Isolate::Current(); |
25 // We only expect this method to be called from within the isolate itself. | 25 // We only expect this method to be called from within the isolate itself. |
26 ASSERT(isolate->thread_registry() == this); | 26 ASSERT(isolate->thread_registry() == this); |
27 // TODO(koda): Rename Thread::PrepareForGC and call it here? | 27 // TODO(koda): Rename Thread::PrepareForGC and call it here? |
28 --remaining_; // Exclude this thread from the count. | 28 --remaining_; // Exclude this thread from the count. |
29 // Ensure the main mutator will reach a safepoint (could be running Dart). | 29 // Ensure the main mutator will reach a safepoint (could be running Dart). |
30 if (Thread::Current() != isolate->mutator_thread()) { | 30 if (!isolate->MutatorThreadIsCurrentThread()) { |
31 isolate->ScheduleInterrupts(Isolate::kVMInterrupt); | 31 isolate->ScheduleInterrupts(Isolate::kVMInterrupt); |
32 } | 32 } |
33 while (remaining_ > 0) { | 33 while (remaining_ > 0) { |
34 ml.Wait(Monitor::kNoTimeout); | 34 ml.Wait(Monitor::kNoTimeout); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 void ThreadRegistry::ResumeAllThreads() { | 39 void ThreadRegistry::ResumeAllThreads() { |
40 MonitorLocker ml(monitor_); | 40 MonitorLocker ml(monitor_); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 for (int i = 0; i < entries_.length(); ++i) { | 75 for (int i = 0; i < entries_.length(); ++i) { |
76 const Entry& entry = entries_[i]; | 76 const Entry& entry = entries_[i]; |
77 if (entry.scheduled) { | 77 if (entry.scheduled) { |
78 ++count; | 78 ++count; |
79 } | 79 } |
80 } | 80 } |
81 return count; | 81 return count; |
82 } | 82 } |
83 | 83 |
84 } // namespace dart | 84 } // namespace dart |
OLD | NEW |