| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 bool Locker::IsActive() { | 97 bool Locker::IsActive() { |
| 98 return active_; | 98 return active_; |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 Locker::~Locker() { | 102 Locker::~Locker() { |
| 103 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 103 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 104 if (has_lock_) { | 104 if (has_lock_) { |
| 105 if (isolate_->IsDefaultIsolate()) { | 105 if (isolate_->IsDefaultIsolate()) { |
| 106 isolate_->Exit(); | 106 isolate_->Exit(false); |
| 107 } | 107 } |
| 108 if (top_level_) { | 108 if (top_level_) { |
| 109 isolate_->thread_manager()->FreeThreadResources(); | 109 isolate_->thread_manager()->FreeThreadResources(); |
| 110 } else { | 110 } else { |
| 111 isolate_->thread_manager()->ArchiveThread(); | 111 isolate_->thread_manager()->ArchiveThread(); |
| 112 } | 112 } |
| 113 isolate_->thread_manager()->Unlock(); | 113 isolate_->thread_manager()->Unlock(); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 Unlocker::Unlocker(v8::Isolate* isolate) | 118 Unlocker::Unlocker(v8::Isolate* isolate) |
| 119 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { | 119 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { |
| 120 if (isolate_ == NULL) { | 120 if (isolate_ == NULL) { |
| 121 isolate_ = i::Isolate::GetDefaultIsolateForLocking(); | 121 isolate_ = i::Isolate::GetDefaultIsolateForLocking(); |
| 122 } | 122 } |
| 123 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 123 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 124 if (isolate_->IsDefaultIsolate()) { | 124 if (isolate_->IsDefaultIsolate()) { |
| 125 isolate_->Exit(); | 125 // Small hack to make sure ArchiveThread does not see an unlocked |
| 126 // view of the isolate. |
| 127 isolate_->Exit(false); |
| 126 } | 128 } |
| 127 isolate_->thread_manager()->ArchiveThread(); | 129 isolate_->thread_manager()->ArchiveThread(); |
| 128 isolate_->thread_manager()->Unlock(); | 130 isolate_->thread_manager()->Unlock(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 | 133 |
| 132 Unlocker::~Unlocker() { | 134 Unlocker::~Unlocker() { |
| 133 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); | 135 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 134 isolate_->thread_manager()->Lock(); | 136 isolate_->thread_manager()->Lock(); |
| 135 isolate_->thread_manager()->RestoreThread(); | 137 isolate_->thread_manager()->RestoreThread(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 state->set_terminate_on_restore(false); | 205 state->set_terminate_on_restore(false); |
| 204 } | 206 } |
| 205 state->set_id(ThreadId::Invalid()); | 207 state->set_id(ThreadId::Invalid()); |
| 206 state->Unlink(); | 208 state->Unlink(); |
| 207 state->LinkInto(ThreadState::FREE_LIST); | 209 state->LinkInto(ThreadState::FREE_LIST); |
| 208 return true; | 210 return true; |
| 209 } | 211 } |
| 210 | 212 |
| 211 | 213 |
| 212 void ThreadManager::Lock() { | 214 void ThreadManager::Lock() { |
| 215 ASSERT(!IsLockedByCurrentThread()); |
| 213 mutex_->Lock(); | 216 mutex_->Lock(); |
| 214 mutex_owner_ = ThreadId::Current(); | 217 mutex_owner_ = ThreadId::Current(); |
| 215 ASSERT(IsLockedByCurrentThread()); | 218 ASSERT(IsLockedByCurrentThread()); |
| 216 } | 219 } |
| 217 | 220 |
| 218 | 221 |
| 219 void ThreadManager::Unlock() { | 222 void ThreadManager::Unlock() { |
| 223 ASSERT(IsLockedByCurrentThread()); |
| 220 mutex_owner_ = ThreadId::Invalid(); | 224 mutex_owner_ = ThreadId::Invalid(); |
| 221 mutex_->Unlock(); | 225 mutex_->Unlock(); |
| 222 } | 226 } |
| 223 | 227 |
| 224 | 228 |
| 225 static int ArchiveSpacePerThread() { | 229 static int ArchiveSpacePerThread() { |
| 226 return HandleScopeImplementer::ArchiveSpacePerThread() + | 230 return HandleScopeImplementer::ArchiveSpacePerThread() + |
| 227 Isolate::ArchiveSpacePerThread() + | 231 Isolate::ArchiveSpacePerThread() + |
| 228 #ifdef ENABLE_DEBUGGER_SUPPORT | 232 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 229 Debug::ArchiveSpacePerThread() + | 233 Debug::ArchiveSpacePerThread() + |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // Acknowledge the preemption by the receiving thread. | 467 // Acknowledge the preemption by the receiving thread. |
| 464 void ContextSwitcher::PreemptionReceived() { | 468 void ContextSwitcher::PreemptionReceived() { |
| 465 ASSERT(Locker::IsLocked()); | 469 ASSERT(Locker::IsLocked()); |
| 466 // There is currently no accounting being done for this. But could be in the | 470 // There is currently no accounting being done for this. But could be in the |
| 467 // future, which is why we leave this in. | 471 // future, which is why we leave this in. |
| 468 } | 472 } |
| 469 | 473 |
| 470 | 474 |
| 471 } // namespace internal | 475 } // namespace internal |
| 472 } // namespace v8 | 476 } // namespace v8 |
| OLD | NEW |