V8 Project
v8threads.h
Go to the documentation of this file.
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.
4 
5 #ifndef V8_V8THREADS_H_
6 #define V8_V8THREADS_H_
7 
8 namespace v8 {
9 namespace internal {
10 
11 
12 class ThreadState {
13  public:
14  // Returns NULL after the last one.
15  ThreadState* Next();
16 
18 
19  void LinkInto(List list);
20  void Unlink();
21 
22  // Id of thread.
23  void set_id(ThreadId id) { id_ = id; }
24  ThreadId id() { return id_; }
25 
26  // Should the thread be terminated when it is restored?
30  }
31 
32  // Get data area for archiving a thread.
33  char* data() { return data_; }
34 
35  private:
36  explicit ThreadState(ThreadManager* thread_manager);
37  ~ThreadState();
38 
39  void AllocateSpace();
40 
43  char* data_;
46 
48 
49  friend class ThreadManager;
50 };
51 
52 
53 // Defined in isolate.h.
54 class ThreadLocalTop;
55 
56 
58  public:
59  // ThreadLocalTop may be only available during this call.
60  virtual void VisitThread(Isolate* isolate, ThreadLocalTop* top) = 0;
61 
62  protected:
63  virtual ~ThreadVisitor() {}
64 };
65 
66 
68  public:
69  void Lock();
70  void Unlock();
71 
72  void ArchiveThread();
73  bool RestoreThread();
74  void FreeThreadResources();
75  bool IsArchived();
76 
77  void Iterate(ObjectVisitor* v);
80  return mutex_owner_.Equals(ThreadId::Current());
81  }
82 
84 
85  void TerminateExecution(ThreadId thread_id);
86 
87  // Iterate over in-use states.
90 
91  private:
92  ThreadManager();
94 
95  void DeleteThreadStateList(ThreadState* anchor);
96 
97  void EagerlyArchiveThread();
98 
99  base::Mutex mutex_;
103 
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
106  // and unlinking.
107  // Head of linked list of free states.
109  // Head of linked list of states in use.
111 
113 
114  friend class Isolate;
115  friend class ThreadState;
116 };
117 
118 
119 } } // namespace v8::internal
120 
121 #endif // V8_V8THREADS_H_
static ThreadId Current()
Definition: isolate.h:185
void IterateArchivedThreads(ThreadVisitor *v)
Definition: v8threads.cc:342
ThreadState * FirstThreadStateInUse()
Definition: v8threads.cc:231
ThreadState * lazily_archived_thread_state_
Definition: v8threads.h:102
ThreadState * in_use_anchor_
Definition: v8threads.h:110
void TerminateExecution(ThreadId thread_id)
Definition: v8threads.cc:358
void DeleteThreadStateList(ThreadState *anchor)
Definition: v8threads.cc:262
ThreadState * free_anchor_
Definition: v8threads.h:108
void Iterate(ObjectVisitor *v)
Definition: v8threads.cc:329
ThreadState * GetFreeThreadState()
Definition: v8threads.cc:219
void set_id(ThreadId id)
Definition: v8threads.h:23
ThreadState * previous_
Definition: v8threads.h:45
void LinkInto(List list)
Definition: v8threads.cc:208
void set_terminate_on_restore(bool terminate_on_restore)
Definition: v8threads.h:28
ThreadState * next_
Definition: v8threads.h:44
ThreadState * Next()
Definition: v8threads.cc:236
ThreadManager * thread_manager_
Definition: v8threads.h:47
ThreadState(ThreadManager *thread_manager)
Definition: v8threads.cc:182
virtual void VisitThread(Isolate *isolate, ThreadLocalTop *top)=0
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20