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_
14 // Returns NULL after the last one.
17 enum List {FREE_LIST, IN_USE_LIST};
19 void LinkInto(List list);
23 void set_id(ThreadId id) { id_ = id; }
24 ThreadId id() { return id_; }
26 // Should the thread be terminated when it is restored?
27 bool terminate_on_restore() { return terminate_on_restore_; }
28 void set_terminate_on_restore(bool terminate_on_restore) {
29 terminate_on_restore_ = terminate_on_restore;
32 // Get data area for archiving a thread.
33 char* data() { return data_; }
36 explicit ThreadState(ThreadManager* thread_manager);
42 bool terminate_on_restore_;
45 ThreadState* previous_;
47 ThreadManager* thread_manager_;
49 friend class ThreadManager;
53 // Defined in isolate.h.
59 // ThreadLocalTop may be only available during this call.
60 virtual void VisitThread(Isolate* isolate, ThreadLocalTop* top) = 0;
63 virtual ~ThreadVisitor() {}
74 void FreeThreadResources();
77 void Iterate(ObjectVisitor* v);
78 void IterateArchivedThreads(ThreadVisitor* v);
79 bool IsLockedByCurrentThread() {
80 return mutex_owner_.Equals(ThreadId::Current());
85 void TerminateExecution(ThreadId thread_id);
87 // Iterate over in-use states.
88 ThreadState* FirstThreadStateInUse();
89 ThreadState* GetFreeThreadState();
95 void DeleteThreadStateList(ThreadState* anchor);
97 void EagerlyArchiveThread();
100 ThreadId mutex_owner_;
101 ThreadId lazily_archived_thread_;
102 ThreadState* lazily_archived_thread_state_;
104 // In the following two lists there is always at least one object on the list.
105 // The first object is a flying anchor that is only there to simplify linking
107 // Head of linked list of free states.
108 ThreadState* free_anchor_;
109 // Head of linked list of states in use.
110 ThreadState* in_use_anchor_;
114 friend class Isolate;
115 friend class ThreadState;
119 } } // namespace v8::internal
121 #endif // V8_V8THREADS_H_