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 { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 60 |
61 | 61 |
62 void ThreadRegistry::ResumeAllThreads() { | 62 void ThreadRegistry::ResumeAllThreads() { |
63 MonitorLocker ml(monitor_); | 63 MonitorLocker ml(monitor_); |
64 ASSERT(in_rendezvous_); | 64 ASSERT(in_rendezvous_); |
65 in_rendezvous_ = false; | 65 in_rendezvous_ = false; |
66 ml.NotifyAll(); | 66 ml.NotifyAll(); |
67 } | 67 } |
68 | 68 |
69 | 69 |
70 void ThreadRegistry::PruneThread(Thread* thread) { | |
71 MonitorLocker ml(monitor_); | |
72 intptr_t length = entries_.length(); | |
73 if (length == 0) { | |
74 return; | |
75 } | |
76 intptr_t found_index = -1; | |
77 for (intptr_t index = 0; index < length; index++) { | |
78 if (entries_.At(index).thread == thread) { | |
79 found_index = index; | |
80 break; | |
81 } | |
82 } | |
83 if (found_index < 0) { | |
84 return; | |
85 } | |
86 if (found_index != (length - 1)) { | |
87 // Swap with last entry. | |
88 entries_.Swap(found_index, length - 1); | |
89 } | |
90 entries_.RemoveLast(); | |
91 } | |
92 | |
93 | |
94 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) | |
95 : index_(0), | |
96 registry_(NULL) { | |
97 Reset(registry); | |
koda
2015/08/20 15:45:14
Wouldn't it be simpler to have a MonitorLocker fie
Cutch
2015/08/20 20:40:19
Acknowledged.
| |
98 } | |
99 | |
100 | |
101 ThreadRegistry::EntryIterator::~EntryIterator() { | |
102 Reset(NULL); | |
103 } | |
104 | |
105 | |
106 void ThreadRegistry::EntryIterator::Reset(ThreadRegistry* registry) { | |
Ivan Posva
2015/08/20 18:00:10
Personally I find resettable iterators confusing t
Cutch
2015/08/20 20:40:19
Reset is now private.
| |
107 // Reset index. | |
108 index_ = 0; | |
109 | |
110 // Unlock old registry. | |
111 if (registry_ != NULL) { | |
112 registry_->monitor_->Exit(); | |
113 } | |
114 | |
115 registry_ = registry; | |
116 | |
117 // Lock new registry. | |
118 if (registry_ != NULL) { | |
119 registry_->monitor_->Enter(); | |
120 } | |
121 } | |
122 | |
123 | |
124 bool ThreadRegistry::EntryIterator::HasNext() const { | |
125 if (registry_ == NULL) { | |
126 return false; | |
127 } | |
128 return index_ < registry_->entries_.length(); | |
129 } | |
130 | |
131 | |
132 const ThreadRegistry::Entry& ThreadRegistry::EntryIterator::Next() { | |
133 ASSERT(HasNext()); | |
134 return registry_->entries_.At(index_++); | |
135 } | |
136 | |
137 | |
70 void ThreadRegistry::CheckSafepointLocked() { | 138 void ThreadRegistry::CheckSafepointLocked() { |
71 int64_t last_round = -1; | 139 int64_t last_round = -1; |
72 while (in_rendezvous_) { | 140 while (in_rendezvous_) { |
73 ASSERT(round_ >= last_round); | 141 ASSERT(round_ >= last_round); |
74 if (round_ != last_round) { | 142 if (round_ != last_round) { |
75 ASSERT((last_round == -1) || (round_ == (last_round + 1))); | 143 ASSERT((last_round == -1) || (round_ == (last_round + 1))); |
76 last_round = round_; | 144 last_round = round_; |
77 // Participate in this round. | 145 // Participate in this round. |
78 // TODO(koda): Rename Thread::PrepareForGC and call it here? | 146 // TODO(koda): Rename Thread::PrepareForGC and call it here? |
79 if (--remaining_ == 0) { | 147 if (--remaining_ == 0) { |
(...skipping 18 matching lines...) Expand all Loading... | |
98 for (int i = 0; i < entries_.length(); ++i) { | 166 for (int i = 0; i < entries_.length(); ++i) { |
99 const Entry& entry = entries_[i]; | 167 const Entry& entry = entries_[i]; |
100 if (entry.scheduled) { | 168 if (entry.scheduled) { |
101 ++count; | 169 ++count; |
102 } | 170 } |
103 } | 171 } |
104 return count; | 172 return count; |
105 } | 173 } |
106 | 174 |
107 } // namespace dart | 175 } // namespace dart |
OLD | NEW |