Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: src/v8threads.cc

Issue 25002004: make v8::Locker not use Isolate::GetCurrent() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24 matching lines...) Expand all
35 #include "regexp-stack.h" 35 #include "regexp-stack.h"
36 36
37 namespace v8 { 37 namespace v8 {
38 38
39 39
40 // Track whether this V8 instance has ever called v8::Locker. This allows the 40 // Track whether this V8 instance has ever called v8::Locker. This allows the
41 // API code to verify that the lock is always held when V8 is being entered. 41 // API code to verify that the lock is always held when V8 is being entered.
42 bool Locker::active_ = false; 42 bool Locker::active_ = false;
43 43
44 44
45 Locker::Locker() {
46 Initialize(i::Isolate::GetDefaultIsolateForLocking());
47 }
48
49
50 // Once the Locker is initialized, the current thread will be guaranteed to have 45 // Once the Locker is initialized, the current thread will be guaranteed to have
51 // the lock for a given isolate. 46 // the lock for a given isolate.
52 void Locker::Initialize(v8::Isolate* isolate) { 47 void Locker::Initialize(v8::Isolate* isolate) {
53 ASSERT(isolate != NULL); 48 ASSERT(isolate != NULL);
54 has_lock_= false; 49 has_lock_= false;
55 top_level_ = true; 50 top_level_ = true;
56 isolate_ = reinterpret_cast<i::Isolate*>(isolate); 51 isolate_ = reinterpret_cast<i::Isolate*>(isolate);
57 // Record that the Locker has been used at least once. 52 // Record that the Locker has been used at least once.
58 active_ = true; 53 active_ = true;
59 // Get the big lock if necessary. 54 // Get the big lock if necessary.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 if (top_level_) { 104 if (top_level_) {
110 isolate_->thread_manager()->FreeThreadResources(); 105 isolate_->thread_manager()->FreeThreadResources();
111 } else { 106 } else {
112 isolate_->thread_manager()->ArchiveThread(); 107 isolate_->thread_manager()->ArchiveThread();
113 } 108 }
114 isolate_->thread_manager()->Unlock(); 109 isolate_->thread_manager()->Unlock();
115 } 110 }
116 } 111 }
117 112
118 113
119 Unlocker::Unlocker() {
120 Initialize(i::Isolate::GetDefaultIsolateForLocking());
121 }
122
123
124 void Unlocker::Initialize(v8::Isolate* isolate) { 114 void Unlocker::Initialize(v8::Isolate* isolate) {
125 ASSERT(isolate != NULL); 115 ASSERT(isolate != NULL);
126 isolate_ = reinterpret_cast<i::Isolate*>(isolate); 116 isolate_ = reinterpret_cast<i::Isolate*>(isolate);
127 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); 117 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread());
128 if (isolate_->IsDefaultIsolate()) { 118 if (isolate_->IsDefaultIsolate()) {
129 isolate_->Exit(); 119 isolate_->Exit();
130 } 120 }
131 isolate_->thread_manager()->ArchiveThread(); 121 isolate_->thread_manager()->ArchiveThread();
132 isolate_->thread_manager()->Unlock(); 122 isolate_->thread_manager()->Unlock();
133 } 123 }
134 124
135 125
136 Unlocker::~Unlocker() { 126 Unlocker::~Unlocker() {
137 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread()); 127 ASSERT(!isolate_->thread_manager()->IsLockedByCurrentThread());
138 isolate_->thread_manager()->Lock(); 128 isolate_->thread_manager()->Lock();
139 isolate_->thread_manager()->RestoreThread(); 129 isolate_->thread_manager()->RestoreThread();
140 if (isolate_->IsDefaultIsolate()) { 130 if (isolate_->IsDefaultIsolate()) {
141 isolate_->Enter(); 131 isolate_->Enter();
142 } 132 }
143 } 133 }
144 134
145 135
146 void Locker::StartPreemption(int every_n_ms) { 136 void Locker::StartPreemption(v8::Isolate* isolate, int every_n_ms) {
147 v8::internal::ContextSwitcher::StartPreemption( 137 v8::internal::ContextSwitcher::StartPreemption(
148 i::Isolate::Current(), every_n_ms); 138 reinterpret_cast<i::Isolate*>(isolate), every_n_ms);
149 } 139 }
150 140
151 141
152 void Locker::StopPreemption() { 142 void Locker::StopPreemption(v8::Isolate* isolate) {
153 v8::internal::ContextSwitcher::StopPreemption(i::Isolate::Current()); 143 v8::internal::ContextSwitcher::StopPreemption(
144 reinterpret_cast<i::Isolate*>(isolate));
154 } 145 }
155 146
156 147
157 namespace internal { 148 namespace internal {
158 149
159 150
160 bool ThreadManager::RestoreThread() { 151 bool ThreadManager::RestoreThread() {
161 ASSERT(IsLockedByCurrentThread()); 152 ASSERT(IsLockedByCurrentThread());
162 // First check whether the current thread has been 'lazily archived', i.e. 153 // First check whether the current thread has been 'lazily archived', i.e.
163 // not archived at all. If that is the case we put the state storage we 154 // not archived at all. If that is the case we put the state storage we
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 472
482 // Acknowledge the preemption by the receiving thread. 473 // Acknowledge the preemption by the receiving thread.
483 void ContextSwitcher::PreemptionReceived() { 474 void ContextSwitcher::PreemptionReceived() {
484 // There is currently no accounting being done for this. But could be in the 475 // There is currently no accounting being done for this. But could be in the
485 // future, which is why we leave this in. 476 // future, which is why we leave this in.
486 } 477 }
487 478
488 479
489 } // namespace internal 480 } // namespace internal
490 } // namespace v8 481 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698