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

Side by Side Diff: src/v8threads.cc

Issue 174056: Add support for forceful termination of JavaScript execution. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8threads.h ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 char* from = state->data(); 144 char* from = state->data();
145 from = HandleScopeImplementer::RestoreThread(from); 145 from = HandleScopeImplementer::RestoreThread(from);
146 from = Top::RestoreThread(from); 146 from = Top::RestoreThread(from);
147 #ifdef ENABLE_DEBUGGER_SUPPORT 147 #ifdef ENABLE_DEBUGGER_SUPPORT
148 from = Debug::RestoreDebug(from); 148 from = Debug::RestoreDebug(from);
149 #endif 149 #endif
150 from = StackGuard::RestoreStackGuard(from); 150 from = StackGuard::RestoreStackGuard(from);
151 from = RegExpStack::RestoreStack(from); 151 from = RegExpStack::RestoreStack(from);
152 from = Bootstrapper::RestoreState(from); 152 from = Bootstrapper::RestoreState(from);
153 Thread::SetThreadLocal(thread_state_key, NULL); 153 Thread::SetThreadLocal(thread_state_key, NULL);
154 if (state->terminate_on_restore()) {
155 StackGuard::TerminateExecution();
156 state->set_terminate_on_restore(false);
157 }
154 state->set_id(kInvalidId); 158 state->set_id(kInvalidId);
155 state->Unlink(); 159 state->Unlink();
156 state->LinkInto(ThreadState::FREE_LIST); 160 state->LinkInto(ThreadState::FREE_LIST);
157 return true; 161 return true;
158 } 162 }
159 163
160 164
161 void ThreadManager::Lock() { 165 void ThreadManager::Lock() {
162 mutex_->Lock(); 166 mutex_->Lock();
163 mutex_owner_.Initialize(ThreadHandle::SELF); 167 mutex_owner_.Initialize(ThreadHandle::SELF);
(...skipping 17 matching lines...) Expand all
181 RegExpStack::ArchiveSpacePerThread() + 185 RegExpStack::ArchiveSpacePerThread() +
182 Bootstrapper::ArchiveSpacePerThread(); 186 Bootstrapper::ArchiveSpacePerThread();
183 } 187 }
184 188
185 189
186 ThreadState* ThreadState::free_anchor_ = new ThreadState(); 190 ThreadState* ThreadState::free_anchor_ = new ThreadState();
187 ThreadState* ThreadState::in_use_anchor_ = new ThreadState(); 191 ThreadState* ThreadState::in_use_anchor_ = new ThreadState();
188 192
189 193
190 ThreadState::ThreadState() : id_(ThreadManager::kInvalidId), 194 ThreadState::ThreadState() : id_(ThreadManager::kInvalidId),
195 terminate_on_restore_(false),
191 next_(this), previous_(this) { 196 next_(this), previous_(this) {
192 } 197 }
193 198
194 199
195 void ThreadState::AllocateSpace() { 200 void ThreadState::AllocateSpace() {
196 data_ = NewArray<char>(ArchiveSpacePerThread()); 201 data_ = NewArray<char>(ArchiveSpacePerThread());
197 } 202 }
198 203
199 204
200 void ThreadState::Unlink() { 205 void ThreadState::Unlink() {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 315 }
311 316
312 317
313 int ThreadManager::CurrentId() { 318 int ThreadManager::CurrentId() {
314 return Thread::GetThreadLocalInt(thread_id_key); 319 return Thread::GetThreadLocalInt(thread_id_key);
315 } 320 }
316 321
317 322
318 void ThreadManager::AssignId() { 323 void ThreadManager::AssignId() {
319 if (!Thread::HasThreadLocal(thread_id_key)) { 324 if (!Thread::HasThreadLocal(thread_id_key)) {
320 Thread::SetThreadLocalInt(thread_id_key, next_id_++); 325 ASSERT(Locker::IsLocked());
326 int thread_id = next_id_++;
327 Thread::SetThreadLocalInt(thread_id_key, thread_id);
328 Top::set_thread_id(thread_id);
329 }
330 }
331
332
333 void ThreadManager::TerminateExecution(int thread_id) {
334 for (ThreadState* state = ThreadState::FirstInUse();
335 state != NULL;
336 state = state->Next()) {
337 if (thread_id == state->id()) {
338 state->set_terminate_on_restore(true);
339 }
321 } 340 }
322 } 341 }
323 342
324 343
325 // This is the ContextSwitcher singleton. There is at most a single thread 344 // This is the ContextSwitcher singleton. There is at most a single thread
326 // running which delivers preemption events to V8 threads. 345 // running which delivers preemption events to V8 threads.
327 ContextSwitcher* ContextSwitcher::singleton_ = NULL; 346 ContextSwitcher* ContextSwitcher::singleton_ = NULL;
328 347
329 348
330 ContextSwitcher::ContextSwitcher(int every_n_ms) 349 ContextSwitcher::ContextSwitcher(int every_n_ms)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // Acknowledge the preemption by the receiving thread. 397 // Acknowledge the preemption by the receiving thread.
379 void ContextSwitcher::PreemptionReceived() { 398 void ContextSwitcher::PreemptionReceived() {
380 ASSERT(Locker::IsLocked()); 399 ASSERT(Locker::IsLocked());
381 // There is currently no accounting being done for this. But could be in the 400 // There is currently no accounting being done for this. But could be in the
382 // future, which is why we leave this in. 401 // future, which is why we leave this in.
383 } 402 }
384 403
385 404
386 } // namespace internal 405 } // namespace internal
387 } // namespace v8 406 } // namespace v8
OLDNEW
« no previous file with comments | « src/v8threads.h ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698