1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_V8THREADS_H_
6 #define V8_V8THREADS_H_
8 #include "src/isolate.h"
16 // Returns NULL after the last one.
19 enum List {FREE_LIST, IN_USE_LIST};
21 void LinkInto(List list);
25 void set_id(ThreadId id) { id_ = id; }
26 ThreadId id() { return id_; }
28 // Should the thread be terminated when it is restored?
29 bool terminate_on_restore() { return terminate_on_restore_; }
30 void set_terminate_on_restore(bool terminate_on_restore) {
31 terminate_on_restore_ = terminate_on_restore;
34 // Get data area for archiving a thread.
35 char* data() { return data_; }
38 explicit ThreadState(ThreadManager* thread_manager);
44 bool terminate_on_restore_;
47 ThreadState* previous_;
49 ThreadManager* thread_manager_;
51 friend class ThreadManager;
55 // Defined in isolate.h.
61 // ThreadLocalTop may be only available during this call.
62 virtual void VisitThread(Isolate* isolate, ThreadLocalTop* top) = 0;
65 virtual ~ThreadVisitor() {}
76 void FreeThreadResources();
79 void Iterate(ObjectVisitor* v);
80 void IterateArchivedThreads(ThreadVisitor* v);
81 bool IsLockedByCurrentThread() {
82 return mutex_owner_.Equals(ThreadId::Current());
87 void TerminateExecution(ThreadId thread_id);
89 // Iterate over in-use states.
90 ThreadState* FirstThreadStateInUse();
91 ThreadState* GetFreeThreadState();
97 void DeleteThreadStateList(ThreadState* anchor);
99 void EagerlyArchiveThread();
102 ThreadId mutex_owner_;
103 ThreadId lazily_archived_thread_;
104 ThreadState* lazily_archived_thread_state_;
106 // In the following two lists there is always at least one object on the list.
107 // The first object is a flying anchor that is only there to simplify linking
109 // Head of linked list of free states.
110 ThreadState* free_anchor_;
111 // Head of linked list of states in use.
112 ThreadState* in_use_anchor_;
116 friend class Isolate;
117 friend class ThreadState;
121 } } // namespace v8::internal
123 #endif // V8_V8THREADS_H_