Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 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 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); | 137 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 138 isolate_->thread_manager()->Lock(); | 138 isolate_->thread_manager()->Lock(); |
| 139 isolate_->thread_manager()->RestoreThread(); | 139 isolate_->thread_manager()->RestoreThread(); |
| 140 if (isolate_->IsDefaultIsolate()) { | 140 if (isolate_->IsDefaultIsolate()) { |
| 141 isolate_->Enter(); | 141 isolate_->Enter(); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 void Locker::StartPreemption(int every_n_ms) { | 146 void Locker::StartPreemption(int every_n_ms) { |
| 147 v8::internal::ContextSwitcher::StartPreemption(every_n_ms); | 147 v8::internal::ContextSwitcher::StartPreemption( |
| 148 i::Isolate::Current(), every_n_ms); | |
|
Sven Panne
2013/09/03 11:38:56
Hmmm, we'll have to think about these: The Locker
| |
| 148 } | 149 } |
| 149 | 150 |
| 150 | 151 |
| 151 void Locker::StopPreemption() { | 152 void Locker::StopPreemption() { |
| 152 v8::internal::ContextSwitcher::StopPreemption(); | 153 v8::internal::ContextSwitcher::StopPreemption(i::Isolate::Current()); |
| 153 } | 154 } |
| 154 | 155 |
| 155 | 156 |
| 156 namespace internal { | 157 namespace internal { |
| 157 | 158 |
| 158 | 159 |
| 159 bool ThreadManager::RestoreThread() { | 160 bool ThreadManager::RestoreThread() { |
| 160 ASSERT(IsLockedByCurrentThread()); | 161 ASSERT(IsLockedByCurrentThread()); |
| 161 // First check whether the current thread has been 'lazily archived', i.e. | 162 // First check whether the current thread has been 'lazily archived', i.e. |
| 162 // not archived at all. If that is the case we put the state storage we | 163 // not archived at all. If that is the case we put the state storage we |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 ContextSwitcher::ContextSwitcher(Isolate* isolate, int every_n_ms) | 431 ContextSwitcher::ContextSwitcher(Isolate* isolate, int every_n_ms) |
| 431 : Thread("v8:CtxtSwitcher"), | 432 : Thread("v8:CtxtSwitcher"), |
| 432 keep_going_(true), | 433 keep_going_(true), |
| 433 sleep_ms_(every_n_ms), | 434 sleep_ms_(every_n_ms), |
| 434 isolate_(isolate) { | 435 isolate_(isolate) { |
| 435 } | 436 } |
| 436 | 437 |
| 437 | 438 |
| 438 // Set the scheduling interval of V8 threads. This function starts the | 439 // Set the scheduling interval of V8 threads. This function starts the |
| 439 // ContextSwitcher thread if needed. | 440 // ContextSwitcher thread if needed. |
| 440 void ContextSwitcher::StartPreemption(int every_n_ms) { | 441 void ContextSwitcher::StartPreemption(Isolate* isolate, int every_n_ms) { |
| 441 Isolate* isolate = Isolate::Current(); | |
| 442 ASSERT(Locker::IsLocked(reinterpret_cast<v8::Isolate*>(isolate))); | 442 ASSERT(Locker::IsLocked(reinterpret_cast<v8::Isolate*>(isolate))); |
| 443 if (isolate->context_switcher() == NULL) { | 443 if (isolate->context_switcher() == NULL) { |
| 444 // If the ContextSwitcher thread is not running at the moment start it now. | 444 // If the ContextSwitcher thread is not running at the moment start it now. |
| 445 isolate->set_context_switcher(new ContextSwitcher(isolate, every_n_ms)); | 445 isolate->set_context_switcher(new ContextSwitcher(isolate, every_n_ms)); |
| 446 isolate->context_switcher()->Start(); | 446 isolate->context_switcher()->Start(); |
| 447 } else { | 447 } else { |
| 448 // ContextSwitcher thread is already running, so we just change the | 448 // ContextSwitcher thread is already running, so we just change the |
| 449 // scheduling interval. | 449 // scheduling interval. |
| 450 isolate->context_switcher()->sleep_ms_ = every_n_ms; | 450 isolate->context_switcher()->sleep_ms_ = every_n_ms; |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 | 454 |
| 455 // Disable preemption of V8 threads. If multiple threads want to use V8 they | 455 // Disable preemption of V8 threads. If multiple threads want to use V8 they |
| 456 // must cooperatively schedule amongst them from this point on. | 456 // must cooperatively schedule amongst them from this point on. |
| 457 void ContextSwitcher::StopPreemption() { | 457 void ContextSwitcher::StopPreemption(Isolate* isolate) { |
| 458 Isolate* isolate = Isolate::Current(); | |
| 459 ASSERT(Locker::IsLocked(reinterpret_cast<v8::Isolate*>(isolate))); | 458 ASSERT(Locker::IsLocked(reinterpret_cast<v8::Isolate*>(isolate))); |
| 460 if (isolate->context_switcher() != NULL) { | 459 if (isolate->context_switcher() != NULL) { |
| 461 // The ContextSwitcher thread is running. We need to stop it and release | 460 // The ContextSwitcher thread is running. We need to stop it and release |
| 462 // its resources. | 461 // its resources. |
| 463 isolate->context_switcher()->keep_going_ = false; | 462 isolate->context_switcher()->keep_going_ = false; |
| 464 // Wait for the ContextSwitcher thread to exit. | 463 // Wait for the ContextSwitcher thread to exit. |
| 465 isolate->context_switcher()->Join(); | 464 isolate->context_switcher()->Join(); |
| 466 // Thread has exited, now we can delete it. | 465 // Thread has exited, now we can delete it. |
| 467 delete(isolate->context_switcher()); | 466 delete(isolate->context_switcher()); |
| 468 isolate->set_context_switcher(NULL); | 467 isolate->set_context_switcher(NULL); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 483 // Acknowledge the preemption by the receiving thread. | 482 // Acknowledge the preemption by the receiving thread. |
| 484 void ContextSwitcher::PreemptionReceived() { | 483 void ContextSwitcher::PreemptionReceived() { |
| 485 ASSERT(Locker::IsLocked(i::Isolate::GetDefaultIsolateForLocking())); | 484 ASSERT(Locker::IsLocked(i::Isolate::GetDefaultIsolateForLocking())); |
| 486 // There is currently no accounting being done for this. But could be in the | 485 // There is currently no accounting being done for this. But could be in the |
| 487 // future, which is why we leave this in. | 486 // future, which is why we leave this in. |
| 488 } | 487 } |
| 489 | 488 |
| 490 | 489 |
| 491 } // namespace internal | 490 } // namespace internal |
| 492 } // namespace v8 | 491 } // namespace v8 |
| OLD | NEW |