| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 // This may be a locker within an unlocker in which case we have to | 68 // This may be a locker within an unlocker in which case we have to |
| 69 // get the saved state for this thread and restore it. | 69 // get the saved state for this thread and restore it. |
| 70 if (isolate_->thread_manager()->RestoreThread()) { | 70 if (isolate_->thread_manager()->RestoreThread()) { |
| 71 top_level_ = false; | 71 top_level_ = false; |
| 72 } else { | 72 } else { |
| 73 internal::ExecutionAccess access(isolate_); | 73 internal::ExecutionAccess access(isolate_); |
| 74 isolate_->stack_guard()->ClearThread(access); | 74 isolate_->stack_guard()->ClearThread(access); |
| 75 isolate_->stack_guard()->InitThread(access); | 75 isolate_->stack_guard()->InitThread(access); |
| 76 } | 76 } |
| 77 if (isolate_->IsDefaultIsolate()) { | |
| 78 // This only enters if not yet entered. | |
| 79 internal::Isolate::EnterDefaultIsolate(); | |
| 80 } | |
| 81 } | 77 } |
| 82 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 78 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 83 } | 79 } |
| 84 | 80 |
| 85 | 81 |
| 86 bool Locker::IsLocked(v8::Isolate* isolate) { | 82 bool Locker::IsLocked(v8::Isolate* isolate) { |
| 87 ASSERT(isolate != NULL); | 83 ASSERT(isolate != NULL); |
| 88 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 84 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 89 return internal_isolate->thread_manager()->IsLockedByCurrentThread(); | 85 return internal_isolate->thread_manager()->IsLockedByCurrentThread(); |
| 90 } | 86 } |
| 91 | 87 |
| 92 | 88 |
| 93 bool Locker::IsActive() { | 89 bool Locker::IsActive() { |
| 94 return active_; | 90 return active_; |
| 95 } | 91 } |
| 96 | 92 |
| 97 | 93 |
| 98 Locker::~Locker() { | 94 Locker::~Locker() { |
| 99 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 95 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 100 if (has_lock_) { | 96 if (has_lock_) { |
| 101 if (isolate_->IsDefaultIsolate()) { | |
| 102 isolate_->Exit(); | |
| 103 } | |
| 104 if (top_level_) { | 97 if (top_level_) { |
| 105 isolate_->thread_manager()->FreeThreadResources(); | 98 isolate_->thread_manager()->FreeThreadResources(); |
| 106 } else { | 99 } else { |
| 107 isolate_->thread_manager()->ArchiveThread(); | 100 isolate_->thread_manager()->ArchiveThread(); |
| 108 } | 101 } |
| 109 isolate_->thread_manager()->Unlock(); | 102 isolate_->thread_manager()->Unlock(); |
| 110 } | 103 } |
| 111 } | 104 } |
| 112 | 105 |
| 113 | 106 |
| 114 void Unlocker::Initialize(v8::Isolate* isolate) { | 107 void Unlocker::Initialize(v8::Isolate* isolate) { |
| 115 ASSERT(isolate != NULL); | 108 ASSERT(isolate != NULL); |
| 116 isolate_ = reinterpret_cast<i::Isolate*>(isolate); | 109 isolate_ = reinterpret_cast<i::Isolate*>(isolate); |
| 117 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); | 110 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 118 if (isolate_->IsDefaultIsolate()) { | |
| 119 isolate_->Exit(); | |
| 120 } | |
| 121 isolate_->thread_manager()->ArchiveThread(); | 111 isolate_->thread_manager()->ArchiveThread(); |
| 122 isolate_->thread_manager()->Unlock(); | 112 isolate_->thread_manager()->Unlock(); |
| 123 } | 113 } |
| 124 | 114 |
| 125 | 115 |
| 126 Unlocker::~Unlocker() { | 116 Unlocker::~Unlocker() { |
| 127 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); | 117 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); |
| 128 isolate_->thread_manager()->Lock(); | 118 isolate_->thread_manager()->Lock(); |
| 129 isolate_->thread_manager()->RestoreThread(); | 119 isolate_->thread_manager()->RestoreThread(); |
| 130 if (isolate_->IsDefaultIsolate()) { | |
| 131 isolate_->Enter(); | |
| 132 } | |
| 133 } | 120 } |
| 134 | 121 |
| 135 | 122 |
| 136 namespace internal { | 123 namespace internal { |
| 137 | 124 |
| 138 | 125 |
| 139 bool ThreadManager::RestoreThread() { | 126 bool ThreadManager::RestoreThread() { |
| 140 ASSERT(IsLockedByCurrentThread()); | 127 ASSERT(IsLockedByCurrentThread()); |
| 141 // First check whether the current thread has been 'lazily archived', i.e. | 128 // First check whether the current thread has been 'lazily archived', i.e. |
| 142 // not archived at all. If that is the case we put the state storage we | 129 // not archived at all. If that is the case we put the state storage we |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 state = state->Next()) { | 389 state = state->Next()) { |
| 403 if (thread_id.Equals(state->id())) { | 390 if (thread_id.Equals(state->id())) { |
| 404 state->set_terminate_on_restore(true); | 391 state->set_terminate_on_restore(true); |
| 405 } | 392 } |
| 406 } | 393 } |
| 407 } | 394 } |
| 408 | 395 |
| 409 | 396 |
| 410 } // namespace internal | 397 } // namespace internal |
| 411 } // namespace v8 | 398 } // namespace v8 |
| OLD | NEW |