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

Side by Side Diff: runtime/vm/thread_interrupter.cc

Issue 1758503002: Make the lock/unlock and Enter/Exit methods in Mutex and Monitor private so taht we always use the … (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review-comments Created 4 years, 9 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
« no previous file with comments | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/thread_interrupter.h" 5 #include "vm/thread_interrupter.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 #include "vm/simulator.h" 10 #include "vm/simulator.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 void ThreadInterrupter::Shutdown() { 92 void ThreadInterrupter::Shutdown() {
93 { 93 {
94 MonitorLocker shutdown_ml(monitor_); 94 MonitorLocker shutdown_ml(monitor_);
95 if (shutdown_) { 95 if (shutdown_) {
96 // Already shutdown. 96 // Already shutdown.
97 return; 97 return;
98 } 98 }
99 shutdown_ = true; 99 shutdown_ = true;
100 // Notify. 100 // Notify.
101 monitor_->Notify(); 101 shutdown_ml.Notify();
102 ASSERT(initialized_); 102 ASSERT(initialized_);
103 if (FLAG_trace_thread_interrupter) { 103 if (FLAG_trace_thread_interrupter) {
104 OS::Print("ThreadInterrupter shutting down.\n"); 104 OS::Print("ThreadInterrupter shutting down.\n");
105 } 105 }
106 } 106 }
107 107
108 // Join the thread. 108 // Join the thread.
109 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); 109 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId);
110 OSThread::Join(interrupter_thread_id_); 110 OSThread::Join(interrupter_thread_id_);
111 interrupter_thread_id_ = OSThread::kInvalidThreadJoinId; 111 interrupter_thread_id_ = OSThread::kInvalidThreadJoinId;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Woken up from deep sleep. 176 // Woken up from deep sleep.
177 ASSERT(interrupted_thread_count == 0); 177 ASSERT(interrupted_thread_count == 0);
178 // Return to regular interrupts. 178 // Return to regular interrupts.
179 current_wait_time_ = interrupt_period_; 179 current_wait_time_ = interrupt_period_;
180 } 180 }
181 181
182 // Reset count before interrupting any threads. 182 // Reset count before interrupting any threads.
183 interrupted_thread_count = 0; 183 interrupted_thread_count = 0;
184 184
185 // Temporarily drop the monitor while we interrupt threads. 185 // Temporarily drop the monitor while we interrupt threads.
186 monitor_->Exit(); 186 wait_ml.Exit();
187 187
188 { 188 {
189 OSThreadIterator it; 189 OSThreadIterator it;
190 while (it.HasNext()) { 190 while (it.HasNext()) {
191 OSThread* thread = it.Next(); 191 OSThread* thread = it.Next();
192 if (thread->ThreadInterruptsEnabled()) { 192 if (thread->ThreadInterruptsEnabled()) {
193 interrupted_thread_count++; 193 interrupted_thread_count++;
194 InterruptThread(thread); 194 InterruptThread(thread);
195 } 195 }
196 } 196 }
197 } 197 }
198 198
199 // Take the monitor lock again. 199 // Take the monitor lock again.
200 monitor_->Enter(); 200 wait_ml.Enter();
201 201
202 // Now that we have the lock, check if we were signaled to wake up while 202 // Now that we have the lock, check if we were signaled to wake up while
203 // interrupting threads. 203 // interrupting threads.
204 if (!woken_up_ && (interrupted_thread_count == 0)) { 204 if (!woken_up_ && (interrupted_thread_count == 0)) {
205 // No threads were interrupted and we were not signaled to interrupt 205 // No threads were interrupted and we were not signaled to interrupt
206 // new threads. In order to reduce unnecessary CPU load, we will wait 206 // new threads. In order to reduce unnecessary CPU load, we will wait
207 // until we are notified before attempting to interrupt again. 207 // until we are notified before attempting to interrupt again.
208 current_wait_time_ = Monitor::kNoTimeout; 208 current_wait_time_ = Monitor::kNoTimeout;
209 continue; 209 continue;
210 } 210 }
(...skipping 11 matching lines...) Expand all
222 // Signal to main thread we are exiting. 222 // Signal to main thread we are exiting.
223 MonitorLocker shutdown_ml(monitor_); 223 MonitorLocker shutdown_ml(monitor_);
224 thread_running_ = false; 224 thread_running_ = false;
225 shutdown_ml.Notify(); 225 shutdown_ml.Notify();
226 } 226 }
227 } 227 }
228 228
229 #endif // !PRODUCT 229 #endif // !PRODUCT
230 230
231 } // namespace dart 231 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698