v8
3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
Main Page
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
v8threads.h
Go to the documentation of this file.
1
// Copyright 2012 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
// * Redistributions of source code must retain the above copyright
7
// notice, this list of conditions and the following disclaimer.
8
// * Redistributions in binary form must reproduce the above
9
// copyright notice, this list of conditions and the following
10
// disclaimer in the documentation and/or other materials provided
11
// with the distribution.
12
// * Neither the name of Google Inc. nor the names of its
13
// contributors may be used to endorse or promote products derived
14
// from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
#ifndef V8_V8THREADS_H_
29
#define V8_V8THREADS_H_
30
31
namespace
v8 {
32
namespace
internal {
33
34
35
class
ThreadState
{
36
public
:
37
// Returns NULL after the last one.
38
ThreadState
*
Next
();
39
40
enum
List
{
FREE_LIST
,
IN_USE_LIST
};
41
42
void
LinkInto
(
List
list);
43
void
Unlink
();
44
45
// Id of thread.
46
void
set_id
(
ThreadId
id
) { id_ =
id
; }
47
ThreadId
id
() {
return
id_; }
48
49
// Should the thread be terminated when it is restored?
50
bool
terminate_on_restore
() {
return
terminate_on_restore_; }
51
void
set_terminate_on_restore
(
bool
terminate_on_restore
) {
52
terminate_on_restore_ =
terminate_on_restore
;
53
}
54
55
// Get data area for archiving a thread.
56
char
*
data
() {
return
data_; }
57
58
private
:
59
explicit
ThreadState
(
ThreadManager
* thread_manager);
60
~
ThreadState
();
61
62
void
AllocateSpace();
63
64
ThreadId
id_;
65
bool
terminate_on_restore_;
66
char
* data_;
67
ThreadState
* next_;
68
ThreadState
* previous_;
69
70
ThreadManager
* thread_manager_;
71
72
friend
class
ThreadManager
;
73
};
74
75
76
// Defined in isolate.h.
77
class
ThreadLocalTop;
78
79
80
class
ThreadVisitor
{
81
public
:
82
// ThreadLocalTop may be only available during this call.
83
virtual
void
VisitThread
(
Isolate
* isolate, ThreadLocalTop* top) = 0;
84
85
protected
:
86
virtual
~ThreadVisitor
() {}
87
};
88
89
90
class
ThreadManager
{
91
public
:
92
void
Lock
();
93
void
Unlock
();
94
95
void
ArchiveThread
();
96
bool
RestoreThread
();
97
void
FreeThreadResources
();
98
bool
IsArchived
();
99
100
void
Iterate
(ObjectVisitor* v);
101
void
IterateArchivedThreads
(
ThreadVisitor
* v);
102
bool
IsLockedByCurrentThread
() {
103
return
mutex_owner_.Equals(
ThreadId::Current
());
104
}
105
106
ThreadId
CurrentId
();
107
108
void
TerminateExecution
(
ThreadId
thread_id);
109
110
// Iterate over in-use states.
111
ThreadState
*
FirstThreadStateInUse
();
112
ThreadState
*
GetFreeThreadState
();
113
114
private
:
115
ThreadManager
();
116
~
ThreadManager
();
117
118
void
DeleteThreadStateList(
ThreadState
* anchor);
119
120
void
EagerlyArchiveThread();
121
122
Mutex
* mutex_;
123
ThreadId
mutex_owner_;
124
ThreadId
lazily_archived_thread_;
125
ThreadState
* lazily_archived_thread_state_;
126
127
// In the following two lists there is always at least one object on the list.
128
// The first object is a flying anchor that is only there to simplify linking
129
// and unlinking.
130
// Head of linked list of free states.
131
ThreadState
* free_anchor_;
132
// Head of linked list of states in use.
133
ThreadState
* in_use_anchor_;
134
135
Isolate
* isolate_;
136
137
friend
class
Isolate
;
138
friend
class
ThreadState
;
139
};
140
141
142
// The ContextSwitcher thread is used to schedule regular preemptions to
143
// multiple running V8 threads. Generally it is necessary to call
144
// StartPreemption if there is more than one thread running. If not, a single
145
// JavaScript can take full control of V8 and not allow other threads to run.
146
class
ContextSwitcher
:
public
Thread
{
147
public
:
148
// Set the preemption interval for the ContextSwitcher thread.
149
static
void
StartPreemption
(
int
every_n_ms);
150
151
// Stop sending preemption requests to threads.
152
static
void
StopPreemption
();
153
154
// Preempted thread needs to call back to the ContextSwitcher to acknowledge
155
// the handling of a preemption request.
156
static
void
PreemptionReceived
();
157
158
private
:
159
ContextSwitcher
(
Isolate
* isolate,
int
every_n_ms);
160
161
Isolate
* isolate()
const
{
return
isolate_; }
162
163
void
Run();
164
165
bool
keep_going_;
166
int
sleep_ms_;
167
Isolate
* isolate_;
168
};
169
170
} }
// namespace v8::internal
171
172
#endif // V8_V8THREADS_H_
v8::internal::List
Definition:
globals.h:368
v8::internal::ThreadManager::CurrentId
ThreadId CurrentId()
Definition:
v8threads.cc:411
v8::internal::ThreadState::LinkInto
void LinkInto(List list)
Definition:
v8threads.cc:264
v8::internal::ThreadState::List
List
Definition:
v8threads.h:40
v8::internal::ThreadManager::Unlock
void Unlock()
Definition:
v8threads.cc:219
v8::internal::ThreadManager::IterateArchivedThreads
void IterateArchivedThreads(ThreadVisitor *v)
Definition:
v8threads.cc:400
v8::internal::ThreadState::set_id
void set_id(ThreadId id)
Definition:
v8threads.h:46
v8::internal::ThreadManager::TerminateExecution
void TerminateExecution(ThreadId thread_id)
Definition:
v8threads.cc:416
v8::internal::Thread
Definition:
platform.h:449
v8::internal::ThreadManager::ArchiveThread
void ArchiveThread()
Definition:
v8threads.cc:331
v8::internal::ThreadState::FREE_LIST
Definition:
v8threads.h:40
v8::internal::ThreadManager::IsArchived
bool IsArchived()
Definition:
v8threads.cc:381
v8::internal::ContextSwitcher::PreemptionReceived
static void PreemptionReceived()
Definition:
v8threads.cc:481
v8::internal::ThreadId::Current
static ThreadId Current()
Definition:
isolate.h:154
v8::internal::ThreadState::terminate_on_restore
bool terminate_on_restore()
Definition:
v8threads.h:50
v8::internal::ContextSwitcher
Definition:
v8threads.h:146
v8::internal::Mutex
Definition:
platform.h:548
v8::internal::ThreadManager
Definition:
v8threads.h:90
v8::internal::ThreadId
Definition:
isolate.h:148
v8::internal::ThreadManager::RestoreThread
bool RestoreThread()
Definition:
v8threads.cc:155
v8::internal::ThreadManager::Iterate
void Iterate(ObjectVisitor *v)
Definition:
v8threads.cc:387
v8::internal::ThreadManager::IsLockedByCurrentThread
bool IsLockedByCurrentThread()
Definition:
v8threads.h:102
v8::internal::ThreadManager::GetFreeThreadState
ThreadState * GetFreeThreadState()
Definition:
v8threads.cc:275
v8::internal::ThreadVisitor::VisitThread
virtual void VisitThread(Isolate *isolate, ThreadLocalTop *top)=0
v8::internal::ThreadState
Definition:
v8threads.h:35
v8::internal::ThreadManager::FreeThreadResources
void FreeThreadResources()
Definition:
v8threads.cc:369
v8::internal::ThreadState::data
char * data()
Definition:
v8threads.h:56
v8::internal::ContextSwitcher::StopPreemption
static void StopPreemption()
Definition:
v8threads.cc:454
v8::internal::ContextSwitcher::StartPreemption
static void StartPreemption(int every_n_ms)
Definition:
v8threads.cc:437
v8::internal::ThreadState::id
ThreadId id()
Definition:
v8threads.h:47
v8::internal::ThreadState::Unlink
void Unlink()
Definition:
v8threads.cc:258
v8::internal::ThreadManager::Lock
void Lock()
Definition:
v8threads.cc:212
v8::internal::Isolate
Definition:
isolate.h:359
v8::internal::ThreadState::set_terminate_on_restore
void set_terminate_on_restore(bool terminate_on_restore)
Definition:
v8threads.h:51
v8::internal::ThreadVisitor
Definition:
v8threads.h:80
v8::internal::ThreadManager::FirstThreadStateInUse
ThreadState * FirstThreadStateInUse()
Definition:
v8threads.cc:287
v8::internal::ThreadState::Next
ThreadState * Next()
Definition:
v8threads.cc:292
v8::internal::ThreadState::IN_USE_LIST
Definition:
v8threads.h:40
v8::internal::ThreadVisitor::~ThreadVisitor
virtual ~ThreadVisitor()
Definition:
v8threads.h:86
src
v8threads.h
Generated on Sat Jun 7 2014 23:30:01 for v8 by
1.8.6