Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 // Record that the Locker has been used at least once. | 54 // Record that the Locker has been used at least once. |
| 55 active_ = true; | 55 active_ = true; |
| 56 // Get the big lock if necessary. | 56 // Get the big lock if necessary. |
| 57 if (!isolate_->thread_manager()->IsLockedByCurrentThread()) { | 57 if (!isolate_->thread_manager()->IsLockedByCurrentThread()) { |
| 58 isolate_->thread_manager()->Lock(); | 58 isolate_->thread_manager()->Lock(); |
| 59 has_lock_ = true; | 59 has_lock_ = true; |
| 60 | 60 |
| 61 // Make sure that V8 is initialized. Archiving of threads interferes | 61 // Make sure that V8 is initialized. Archiving of threads interferes |
| 62 // with deserialization by adding additional root pointers, so we must | 62 // with deserialization by adding additional root pointers, so we must |
| 63 // initialize here, before anyone can call ~Locker() or Unlocker(). | 63 // initialize here, before anyone can call ~Locker() or Unlocker(). |
| 64 if (isolate_->IsDefaultIsolate()) { | 64 if (!isolate_->IsInitialized()) { |
| 65 // This only enters if not yet entered. | |
| 66 internal::Isolate::EnterDefaultIsolate(); | |
| 67 } else if (!isolate_->IsInitialized()) { | |
| 68 isolate_->Enter(); | 65 isolate_->Enter(); |
| 69 V8::Initialize(); | 66 V8::Initialize(); |
| 70 isolate_->Exit(); | 67 isolate_->Exit(); |
| 71 } | 68 } |
| 72 | 69 |
| 73 // This may be a locker within an unlocker in which case we have to | 70 // This may be a locker within an unlocker in which case we have to |
| 74 // get the saved state for this thread and restore it. | 71 // get the saved state for this thread and restore it. |
| 75 if (isolate_->thread_manager()->RestoreThread()) { | 72 if (isolate_->thread_manager()->RestoreThread()) { |
| 76 top_level_ = false; | 73 top_level_ = false; |
| 77 } else { | 74 } else { |
| 78 internal::ExecutionAccess access(isolate_); | 75 internal::ExecutionAccess access(isolate_); |
| 79 isolate_->stack_guard()->ClearThread(access); | 76 isolate_->stack_guard()->ClearThread(access); |
| 80 isolate_->stack_guard()->InitThread(access); | 77 isolate_->stack_guard()->InitThread(access); |
| 81 } | 78 } |
| 79 if (isolate_->IsDefaultIsolate()) { | |
| 80 // This only enters if not yet entered. | |
| 81 internal::Isolate::EnterDefaultIsolate(); | |
| 82 } | |
| 82 } | 83 } |
| 83 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 84 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 84 } | 85 } |
| 85 | 86 |
| 86 | 87 |
| 87 bool Locker::IsLocked(v8::Isolate* isolate) { | 88 bool Locker::IsLocked(v8::Isolate* isolate) { |
| 88 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 89 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 89 if (internal_isolate == NULL) { | 90 if (internal_isolate == NULL) { |
| 90 internal_isolate = i::Isolate::GetDefaultIsolateForLocking(); | 91 internal_isolate = i::Isolate::GetDefaultIsolateForLocking(); |
| 91 } | 92 } |
| 92 return internal_isolate->thread_manager()->IsLockedByCurrentThread(); | 93 return internal_isolate->thread_manager()->IsLockedByCurrentThread(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 | 96 |
| 96 Locker::~Locker() { | 97 Locker::~Locker() { |
| 97 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 98 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 98 if (has_lock_) { | 99 if (has_lock_) { |
| 100 if (isolate_->IsDefaultIsolate()) { | |
| 101 isolate_->Exit(); | |
| 102 } | |
| 99 if (top_level_) { | 103 if (top_level_) { |
| 100 isolate_->thread_manager()->FreeThreadResources(); | 104 isolate_->thread_manager()->FreeThreadResources(); |
| 101 } else { | 105 } else { |
| 102 isolate_->thread_manager()->ArchiveThread(); | 106 isolate_->thread_manager()->ArchiveThread(); |
| 103 } | 107 } |
| 104 isolate_->thread_manager()->Unlock(); | 108 isolate_->thread_manager()->Unlock(); |
| 105 } | 109 } |
| 106 } | 110 } |
| 107 | 111 |
| 108 | 112 |
| 109 Unlocker::Unlocker(v8::Isolate* isolate) | 113 Unlocker::Unlocker(v8::Isolate* isolate) |
| 110 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { | 114 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { |
| 111 if (isolate_ == NULL) { | 115 if (isolate_ == NULL) { |
| 112 isolate_ = i::Isolate::GetDefaultIsolateForLocking(); | 116 isolate_ = i::Isolate::GetDefaultIsolateForLocking(); |
| 113 } | 117 } |
| 114 | |
| 115 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 118 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 119 if (isolate_->IsDefaultIsolate()) { | |
| 120 isolate_->Exit(); | |
| 121 } | |
| 116 isolate_->thread_manager()->ArchiveThread(); | 122 isolate_->thread_manager()->ArchiveThread(); |
| 117 isolate_->thread_manager()->Unlock(); | 123 isolate_->thread_manager()->Unlock(); |
| 118 } | 124 } |
| 119 | 125 |
| 120 | 126 |
| 121 Unlocker::~Unlocker() { | 127 Unlocker::~Unlocker() { |
| 122 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); | 128 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 123 isolate_->thread_manager()->Lock(); | 129 isolate_->thread_manager()->Lock(); |
| 124 isolate_->thread_manager()->RestoreThread(); | 130 isolate_->thread_manager()->RestoreThread(); |
| 131 if (isolate_->IsDefaultIsolate()) { | |
| 132 isolate_->Enter(); | |
|
Vitaly Repeshko
2011/05/03 16:41:18
Weird indent.
| |
| 133 } | |
| 125 } | 134 } |
| 126 | 135 |
| 127 | 136 |
| 128 void Locker::StartPreemption(int every_n_ms) { | 137 void Locker::StartPreemption(int every_n_ms) { |
| 129 v8::internal::ContextSwitcher::StartPreemption(every_n_ms); | 138 v8::internal::ContextSwitcher::StartPreemption(every_n_ms); |
| 130 } | 139 } |
| 131 | 140 |
| 132 | 141 |
| 133 void Locker::StopPreemption() { | 142 void Locker::StopPreemption() { |
| 134 v8::internal::ContextSwitcher::StopPreemption(); | 143 v8::internal::ContextSwitcher::StopPreemption(); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 // Acknowledge the preemption by the receiving thread. | 455 // Acknowledge the preemption by the receiving thread. |
| 447 void ContextSwitcher::PreemptionReceived() { | 456 void ContextSwitcher::PreemptionReceived() { |
| 448 ASSERT(Locker::IsLocked()); | 457 ASSERT(Locker::IsLocked()); |
| 449 // There is currently no accounting being done for this. But could be in the | 458 // There is currently no accounting being done for this. But could be in the |
| 450 // future, which is why we leave this in. | 459 // future, which is why we leave this in. |
| 451 } | 460 } |
| 452 | 461 |
| 453 | 462 |
| 454 } // namespace internal | 463 } // namespace internal |
| 455 } // namespace v8 | 464 } // namespace v8 |
| OLD | NEW |