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

Unified Diff: runtime/vm/thread.h

Issue 1393423005: Add ThreadIterator for iterating over all Threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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/dart.cc ('k') | runtime/vm/thread.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread.h
diff --git a/runtime/vm/thread.h b/runtime/vm/thread.h
index 4b9b9c9c6ba36d48000881410b6b9c330c8835f3..96c9a6389c555338a7c55e20e356b673c7cbacc8 100644
--- a/runtime/vm/thread.h
+++ b/runtime/vm/thread.h
@@ -153,6 +153,8 @@ class Thread {
static void InitOnceBeforeIsolate();
static void InitOnceAfterObjectAndStubCode();
+ // Called at VM shutdown
+ static void Shutdown();
~Thread();
// The topmost zone used for allocation in this thread.
@@ -413,6 +415,15 @@ LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS)
VMHandles reusable_handles_;
+ // All |Thread|s are registered in the thread list.
+ Thread* thread_list_next_;
+
+ static Thread* thread_list_head_;
+ static Mutex* thread_list_lock_;
+
+ static void AddThreadToList(Thread* thread);
+ static void RemoveThreadFromList(Thread* thread);
+
explicit Thread(bool init_vm_constants = true);
void InitVMConstants();
@@ -446,10 +457,31 @@ REUSABLE_HANDLE_LIST(REUSABLE_FRIEND_DECLARATION)
friend class ApiZone;
friend class Isolate;
friend class StackZone;
+ friend class ThreadIterator;
+ friend class ThreadIteratorTestHelper;
friend class ThreadRegistry;
+
DISALLOW_COPY_AND_ASSIGN(Thread);
};
+
+// Note that this takes the thread list lock, prohibiting threads from coming
+// on- or off-line.
+class ThreadIterator : public ValueObject {
+ public:
+ ThreadIterator();
+ ~ThreadIterator();
+
+ // Returns false when there are no more threads left.
+ bool HasNext() const;
+
+ // Returns the current thread and moves forward.
+ Thread* Next();
+
+ private:
+ Thread* next_;
+};
+
} // namespace dart
#endif // VM_THREAD_H_
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698