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

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

Issue 1260283007: Fix race and limit access to mutator_thread_. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove debug print. Created 5 years, 4 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/thread.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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_registry.h" 5 #include "vm/thread_registry.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 void ThreadRegistry::SafepointThreads() { 12 void ThreadRegistry::SafepointThreads() {
13 MonitorLocker ml(monitor_); 13 MonitorLocker ml(monitor_);
14 // First wait for any older rounds that are still in progress. 14 // First wait for any older rounds that are still in progress.
15 while (in_rendezvous_) { 15 while (in_rendezvous_) {
16 // Assert we are not the organizer trying to nest calls to SafepointThreads. 16 // Assert we are not the organizer trying to nest calls to SafepointThreads.
17 ASSERT(remaining_ > 0); 17 ASSERT(remaining_ > 0);
18 CheckSafepointLocked(); 18 CheckSafepointLocked();
19 } 19 }
20 // Start a new round. 20 // Start a new round.
21 in_rendezvous_ = true; 21 in_rendezvous_ = true;
22 ++round_; // Overflows after 240+ years @ 10^9 safepoints per second. 22 ++round_; // Overflows after 240+ years @ 10^9 safepoints per second.
23 remaining_ = CountScheduledLocked(); 23 remaining_ = CountScheduledLocked();
24 Isolate* isolate = Isolate::Current(); 24 Isolate* isolate = Isolate::Current();
25 // We only expect this method to be called from within the isolate itself. 25 // We only expect this method to be called from within the isolate itself.
26 ASSERT(isolate->thread_registry() == this); 26 ASSERT(isolate->thread_registry() == this);
27 // TODO(koda): Rename Thread::PrepareForGC and call it here? 27 // TODO(koda): Rename Thread::PrepareForGC and call it here?
28 --remaining_; // Exclude this thread from the count. 28 --remaining_; // Exclude this thread from the count.
29 // Ensure the main mutator will reach a safepoint (could be running Dart). 29 // Ensure the main mutator will reach a safepoint (could be running Dart).
30 if (Thread::Current() != isolate->mutator_thread()) { 30 if (!isolate->MutatorThreadIsCurrentThread()) {
31 isolate->ScheduleInterrupts(Isolate::kVMInterrupt); 31 isolate->ScheduleInterrupts(Isolate::kVMInterrupt);
32 } 32 }
33 while (remaining_ > 0) { 33 while (remaining_ > 0) {
34 ml.Wait(Monitor::kNoTimeout); 34 ml.Wait(Monitor::kNoTimeout);
35 } 35 }
36 } 36 }
37 37
38 38
39 void ThreadRegistry::ResumeAllThreads() { 39 void ThreadRegistry::ResumeAllThreads() {
40 MonitorLocker ml(monitor_); 40 MonitorLocker ml(monitor_);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 for (int i = 0; i < entries_.length(); ++i) { 75 for (int i = 0; i < entries_.length(); ++i) {
76 const Entry& entry = entries_[i]; 76 const Entry& entry = entries_[i];
77 if (entry.scheduled) { 77 if (entry.scheduled) {
78 ++count; 78 ++count;
79 } 79 }
80 } 80 }
81 return count; 81 return count;
82 } 82 }
83 83
84 } // namespace dart 84 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698