OLD | NEW |
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 void ThreadInterrupter::InitOnce() { | 63 void ThreadInterrupter::InitOnce() { |
64 ASSERT(!initialized_); | 64 ASSERT(!initialized_); |
65 monitor_ = new Monitor(); | 65 monitor_ = new Monitor(); |
66 ASSERT(monitor_ != NULL); | 66 ASSERT(monitor_ != NULL); |
67 initialized_ = true; | 67 initialized_ = true; |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 void ThreadInterrupter::Startup() { | 71 void ThreadInterrupter::Startup() { |
72 ASSERT(initialized_); | 72 ASSERT(initialized_); |
| 73 if (IsDebuggerAttached()) { |
| 74 MonitorLocker shutdown_ml(monitor_); |
| 75 shutdown_ = true; |
| 76 if (FLAG_trace_thread_interrupter) { |
| 77 OS::PrintErr( |
| 78 "ThreadInterrupter disabled because a debugger is attached.\n"); |
| 79 } |
| 80 return; |
| 81 } |
73 if (FLAG_trace_thread_interrupter) { | 82 if (FLAG_trace_thread_interrupter) { |
74 OS::Print("ThreadInterrupter starting up.\n"); | 83 OS::PrintErr("ThreadInterrupter starting up.\n"); |
75 } | 84 } |
76 ASSERT(interrupter_thread_id_ == OSThread::kInvalidThreadJoinId); | 85 ASSERT(interrupter_thread_id_ == OSThread::kInvalidThreadJoinId); |
77 { | 86 { |
78 MonitorLocker startup_ml(monitor_); | 87 MonitorLocker startup_ml(monitor_); |
79 OSThread::Start("ThreadInterrupter", ThreadMain, 0); | 88 OSThread::Start("ThreadInterrupter", ThreadMain, 0); |
80 while (!thread_running_) { | 89 while (!thread_running_) { |
81 startup_ml.Wait(); | 90 startup_ml.Wait(); |
82 } | 91 } |
83 } | 92 } |
84 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); | 93 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); |
85 if (FLAG_trace_thread_interrupter) { | 94 if (FLAG_trace_thread_interrupter) { |
86 OS::Print("ThreadInterrupter running.\n"); | 95 OS::PrintErr("ThreadInterrupter running.\n"); |
87 } | 96 } |
88 } | 97 } |
89 | 98 |
90 | 99 |
91 void ThreadInterrupter::Shutdown() { | 100 void ThreadInterrupter::Shutdown() { |
92 { | 101 { |
93 MonitorLocker shutdown_ml(monitor_); | 102 MonitorLocker shutdown_ml(monitor_); |
94 if (shutdown_) { | 103 if (shutdown_) { |
95 // Already shutdown. | 104 // Already shutdown. |
96 return; | 105 return; |
97 } | 106 } |
98 shutdown_ = true; | 107 shutdown_ = true; |
99 // Notify. | 108 // Notify. |
100 shutdown_ml.Notify(); | 109 shutdown_ml.Notify(); |
101 ASSERT(initialized_); | 110 ASSERT(initialized_); |
102 if (FLAG_trace_thread_interrupter) { | 111 if (FLAG_trace_thread_interrupter) { |
103 OS::Print("ThreadInterrupter shutting down.\n"); | 112 OS::PrintErr("ThreadInterrupter shutting down.\n"); |
104 } | 113 } |
105 } | 114 } |
106 | 115 |
107 // Join the thread. | 116 // Join the thread. |
108 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); | 117 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); |
109 OSThread::Join(interrupter_thread_id_); | 118 OSThread::Join(interrupter_thread_id_); |
110 interrupter_thread_id_ = OSThread::kInvalidThreadJoinId; | 119 interrupter_thread_id_ = OSThread::kInvalidThreadJoinId; |
111 | 120 |
112 if (FLAG_trace_thread_interrupter) { | 121 if (FLAG_trace_thread_interrupter) { |
113 OS::Print("ThreadInterrupter shut down.\n"); | 122 OS::PrintErr("ThreadInterrupter shut down.\n"); |
114 } | 123 } |
115 } | 124 } |
116 | 125 |
117 | 126 |
118 // Delay between interrupts. | 127 // Delay between interrupts. |
119 void ThreadInterrupter::SetInterruptPeriod(intptr_t period) { | 128 void ThreadInterrupter::SetInterruptPeriod(intptr_t period) { |
120 if (shutdown_) { | 129 if (shutdown_) { |
121 return; | 130 return; |
122 } | 131 } |
123 ASSERT(initialized_); | 132 ASSERT(initialized_); |
(...skipping 18 matching lines...) Expand all Loading... |
142 // Notify the interrupter to wake it from its deep sleep. | 151 // Notify the interrupter to wake it from its deep sleep. |
143 ml.Notify(); | 152 ml.Notify(); |
144 } | 153 } |
145 } | 154 } |
146 | 155 |
147 | 156 |
148 void ThreadInterrupter::ThreadMain(uword parameters) { | 157 void ThreadInterrupter::ThreadMain(uword parameters) { |
149 ASSERT(initialized_); | 158 ASSERT(initialized_); |
150 InstallSignalHandler(); | 159 InstallSignalHandler(); |
151 if (FLAG_trace_thread_interrupter) { | 160 if (FLAG_trace_thread_interrupter) { |
152 OS::Print("ThreadInterrupter thread running.\n"); | 161 OS::PrintErr("ThreadInterrupter thread running.\n"); |
153 } | 162 } |
154 { | 163 { |
155 // Signal to main thread we are ready. | 164 // Signal to main thread we are ready. |
156 MonitorLocker startup_ml(monitor_); | 165 MonitorLocker startup_ml(monitor_); |
157 OSThread* os_thread = OSThread::Current(); | 166 OSThread* os_thread = OSThread::Current(); |
158 ASSERT(os_thread != NULL); | 167 ASSERT(os_thread != NULL); |
159 interrupter_thread_id_ = OSThread::GetCurrentThreadJoinId(os_thread); | 168 interrupter_thread_id_ = OSThread::GetCurrentThreadJoinId(os_thread); |
160 thread_running_ = true; | 169 thread_running_ = true; |
161 startup_ml.Notify(); | 170 startup_ml.Notify(); |
162 } | 171 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 continue; | 217 continue; |
209 } | 218 } |
210 | 219 |
211 woken_up_ = false; | 220 woken_up_ = false; |
212 | 221 |
213 ASSERT(current_wait_time_ != Monitor::kNoTimeout); | 222 ASSERT(current_wait_time_ != Monitor::kNoTimeout); |
214 } | 223 } |
215 } | 224 } |
216 RemoveSignalHandler(); | 225 RemoveSignalHandler(); |
217 if (FLAG_trace_thread_interrupter) { | 226 if (FLAG_trace_thread_interrupter) { |
218 OS::Print("ThreadInterrupter thread exiting.\n"); | 227 OS::PrintErr("ThreadInterrupter thread exiting.\n"); |
219 } | 228 } |
220 { | 229 { |
221 // Signal to main thread we are exiting. | 230 // Signal to main thread we are exiting. |
222 MonitorLocker shutdown_ml(monitor_); | 231 MonitorLocker shutdown_ml(monitor_); |
223 thread_running_ = false; | 232 thread_running_ = false; |
224 shutdown_ml.Notify(); | 233 shutdown_ml.Notify(); |
225 } | 234 } |
226 } | 235 } |
227 | 236 |
228 #endif // !PRODUCT | 237 #endif // !PRODUCT |
229 | 238 |
230 } // namespace dart | 239 } // namespace dart |
OLD | NEW |