OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 StackGuard::ArchiveSpacePerThread() + | 231 StackGuard::ArchiveSpacePerThread() + |
232 RegExpStack::ArchiveSpacePerThread() + | 232 RegExpStack::ArchiveSpacePerThread() + |
233 Bootstrapper::ArchiveSpacePerThread() + | 233 Bootstrapper::ArchiveSpacePerThread() + |
234 Relocatable::ArchiveSpacePerThread(); | 234 Relocatable::ArchiveSpacePerThread(); |
235 } | 235 } |
236 | 236 |
237 | 237 |
238 ThreadState::ThreadState(ThreadManager* thread_manager) | 238 ThreadState::ThreadState(ThreadManager* thread_manager) |
239 : id_(ThreadId::Invalid()), | 239 : id_(ThreadId::Invalid()), |
240 terminate_on_restore_(false), | 240 terminate_on_restore_(false), |
| 241 data_(NULL), |
241 next_(this), | 242 next_(this), |
242 previous_(this), | 243 previous_(this), |
243 thread_manager_(thread_manager) { | 244 thread_manager_(thread_manager) { |
244 } | 245 } |
245 | 246 |
246 | 247 |
| 248 ThreadState::~ThreadState() { |
| 249 DeleteArray<char>(data_); |
| 250 } |
| 251 |
| 252 |
247 void ThreadState::AllocateSpace() { | 253 void ThreadState::AllocateSpace() { |
248 data_ = NewArray<char>(ArchiveSpacePerThread()); | 254 data_ = NewArray<char>(ArchiveSpacePerThread()); |
249 } | 255 } |
250 | 256 |
251 | 257 |
252 void ThreadState::Unlink() { | 258 void ThreadState::Unlink() { |
253 next_->previous_ = previous_; | 259 next_->previous_ = previous_; |
254 previous_->next_ = next_; | 260 previous_->next_ = next_; |
255 } | 261 } |
256 | 262 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 lazily_archived_thread_state_(NULL), | 305 lazily_archived_thread_state_(NULL), |
300 free_anchor_(NULL), | 306 free_anchor_(NULL), |
301 in_use_anchor_(NULL) { | 307 in_use_anchor_(NULL) { |
302 free_anchor_ = new ThreadState(this); | 308 free_anchor_ = new ThreadState(this); |
303 in_use_anchor_ = new ThreadState(this); | 309 in_use_anchor_ = new ThreadState(this); |
304 } | 310 } |
305 | 311 |
306 | 312 |
307 ThreadManager::~ThreadManager() { | 313 ThreadManager::~ThreadManager() { |
308 delete mutex_; | 314 delete mutex_; |
309 delete free_anchor_; | 315 DeleteThreadStateList(free_anchor_); |
310 delete in_use_anchor_; | 316 DeleteThreadStateList(in_use_anchor_); |
311 } | 317 } |
312 | 318 |
313 | 319 |
| 320 void ThreadManager::DeleteThreadStateList(ThreadState* anchor) { |
| 321 // The list starts and ends with the anchor. |
| 322 for (ThreadState* current = anchor->next_; current != anchor;) { |
| 323 ThreadState* next = current->next_; |
| 324 delete current; |
| 325 current = next; |
| 326 } |
| 327 delete anchor; |
| 328 } |
| 329 |
| 330 |
314 void ThreadManager::ArchiveThread() { | 331 void ThreadManager::ArchiveThread() { |
315 ASSERT(lazily_archived_thread_.Equals(ThreadId::Invalid())); | 332 ASSERT(lazily_archived_thread_.Equals(ThreadId::Invalid())); |
316 ASSERT(!IsArchived()); | 333 ASSERT(!IsArchived()); |
317 ASSERT(IsLockedByCurrentThread()); | 334 ASSERT(IsLockedByCurrentThread()); |
318 ThreadState* state = GetFreeThreadState(); | 335 ThreadState* state = GetFreeThreadState(); |
319 state->Unlink(); | 336 state->Unlink(); |
320 Isolate::PerIsolateThreadData* per_thread = | 337 Isolate::PerIsolateThreadData* per_thread = |
321 isolate_->FindOrAllocatePerThreadDataForThisThread(); | 338 isolate_->FindOrAllocatePerThreadDataForThisThread(); |
322 per_thread->set_thread_state(state); | 339 per_thread->set_thread_state(state); |
323 lazily_archived_thread_ = ThreadId::Current(); | 340 lazily_archived_thread_ = ThreadId::Current(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // Acknowledge the preemption by the receiving thread. | 480 // Acknowledge the preemption by the receiving thread. |
464 void ContextSwitcher::PreemptionReceived() { | 481 void ContextSwitcher::PreemptionReceived() { |
465 ASSERT(Locker::IsLocked()); | 482 ASSERT(Locker::IsLocked()); |
466 // There is currently no accounting being done for this. But could be in the | 483 // There is currently no accounting being done for this. But could be in the |
467 // future, which is why we leave this in. | 484 // future, which is why we leave this in. |
468 } | 485 } |
469 | 486 |
470 | 487 |
471 } // namespace internal | 488 } // namespace internal |
472 } // namespace v8 | 489 } // namespace v8 |
OLD | NEW |