Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: runtime/vm/thread_registry.cc

Issue 1293253005: Completely remove InterruptableThreadState and Fix ThreadRegistry leak (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/thread_registry.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_registry.cc
diff --git a/runtime/vm/thread_registry.cc b/runtime/vm/thread_registry.cc
index 885219a80802bdd0e9011cc00e25039719c91214..d4ef68dd07437629a7b469b64fb51f75448a2ffa 100644
--- a/runtime/vm/thread_registry.cc
+++ b/runtime/vm/thread_registry.cc
@@ -67,6 +67,74 @@ void ThreadRegistry::ResumeAllThreads() {
}
+void ThreadRegistry::PruneThread(Thread* thread) {
+ MonitorLocker ml(monitor_);
+ intptr_t length = entries_.length();
+ if (length == 0) {
+ return;
+ }
+ intptr_t found_index = -1;
+ for (intptr_t index = 0; index < length; index++) {
+ if (entries_.At(index).thread == thread) {
+ found_index = index;
+ break;
+ }
+ }
+ if (found_index < 0) {
+ return;
+ }
+ if (found_index != (length - 1)) {
+ // Swap with last entry.
+ entries_.Swap(found_index, length - 1);
+ }
+ entries_.RemoveLast();
+}
+
+
+ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry)
+ : index_(0),
+ registry_(NULL) {
+ Reset(registry);
+}
+
+
+ThreadRegistry::EntryIterator::~EntryIterator() {
+ Reset(NULL);
+}
+
+
+void ThreadRegistry::EntryIterator::Reset(ThreadRegistry* registry) {
+ // Reset index.
+ index_ = 0;
+
+ // Unlock old registry.
+ if (registry_ != NULL) {
+ registry_->monitor_->Exit();
+ }
+
+ registry_ = registry;
+
+ // Lock new registry.
+ if (registry_ != NULL) {
+ registry_->monitor_->Enter();
+ }
+}
+
+
+bool ThreadRegistry::EntryIterator::HasNext() const {
+ if (registry_ == NULL) {
+ return false;
+ }
+ return index_ < registry_->entries_.length();
+}
+
+
+const ThreadRegistry::Entry& ThreadRegistry::EntryIterator::Next() {
+ ASSERT(HasNext());
+ return registry_->entries_.At(index_++);
+}
+
+
void ThreadRegistry::CheckSafepointLocked() {
int64_t last_round = -1;
while (in_rendezvous_) {
« no previous file with comments | « runtime/vm/thread_registry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698