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

Side by Side Diff: runtime/bin/dbg_connection.cc

Issue 10384016: Eliminate busy waiting for debugger connection (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | « runtime/bin/dbg_connection.h ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "bin/dbg_connection.h" 5 #include "bin/dbg_connection.h"
6 #include "bin/dartutils.h" 6 #include "bin/dartutils.h"
7 #include "bin/socket.h" 7 #include "bin/socket.h"
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
11 #include "platform/globals.h" 11 #include "platform/globals.h"
12 #include "platform/json.h" 12 #include "platform/json.h"
13 #include "platform/thread.h" 13 #include "platform/thread.h"
14 #include "platform/utils.h" 14 #include "platform/utils.h"
15 15
16 #include "include/dart_api.h" 16 #include "include/dart_api.h"
17 17
18 18
19 int DebuggerConnectionHandler::listener_fd_ = -1; 19 int DebuggerConnectionHandler::listener_fd_ = -1;
20 int DebuggerConnectionHandler::debugger_fd_ = -1; 20 int DebuggerConnectionHandler::debugger_fd_ = -1;
21 dart::Monitor DebuggerConnectionHandler::is_connected_;
21 MessageBuffer* DebuggerConnectionHandler::msgbuf_ = NULL; 22 MessageBuffer* DebuggerConnectionHandler::msgbuf_ = NULL;
22 23
23 bool DebuggerConnectionHandler::handler_started_ = false; 24 bool DebuggerConnectionHandler::handler_started_ = false;
24 25
25 26
26 // TODO(hausner): Need better error handling. 27 // TODO(hausner): Need better error handling.
27 #define ASSERT_NOT_ERROR(handle) \ 28 #define ASSERT_NOT_ERROR(handle) \
28 ASSERT(!Dart_IsError(handle)) 29 ASSERT(!Dart_IsError(handle))
29 30
30 31
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ASSERT_NOT_ERROR(res); 203 ASSERT_NOT_ERROR(res);
203 ASSERT(Dart_IsString(func_name)); 204 ASSERT(Dart_IsString(func_name));
204 const char* func_name_chars; 205 const char* func_name_chars;
205 Dart_StringToCString(func_name, &func_name_chars); 206 Dart_StringToCString(func_name, &func_name_chars);
206 msg.Printf("%s { \"functionName\" : \"%s\" , ", 207 msg.Printf("%s { \"functionName\" : \"%s\" , ",
207 i > 0 ? "," : "", 208 i > 0 ? "," : "",
208 func_name_chars); 209 func_name_chars);
209 ASSERT(Dart_IsString(script_url)); 210 ASSERT(Dart_IsString(script_url));
210 const char* script_url_chars; 211 const char* script_url_chars;
211 Dart_StringToCString(script_url, &script_url_chars); 212 Dart_StringToCString(script_url, &script_url_chars);
212 msg.Printf("\"location\": { \"scriptId\": \"%s\", \"lineNumber\": %d }}", 213 msg.Printf("\"location\": { \"url\": \"%s\", \"lineNumber\": %d }}",
213 script_url_chars, line_number); 214 script_url_chars, line_number);
214 } 215 }
215 msg.Printf("]}}"); 216 msg.Printf("]}}");
216 Socket::Write(debugger_fd_, msg.buf(), msg.length()); 217 Socket::Write(debugger_fd_, msg.buf(), msg.length());
217 ASSERT(IsValidJSON(msg.buf())); 218 ASSERT(IsValidJSON(msg.buf()));
218 } 219 }
219 220
220 221
221 void DebuggerConnectionHandler::BreakpointHandler(Dart_Breakpoint bpt, 222 void DebuggerConnectionHandler::BreakpointHandler(Dart_Breakpoint bpt,
222 Dart_StackTrace trace) { 223 Dart_StackTrace trace) {
223 // TODO(hausner): rather than busy-waiting, block on the pipe to the 224 {
224 // debugger thread and wait until a debugger connection has been 225 MonitorLocker ml(&is_connected_);
225 // established. 226 while (!IsConnected()) {
226 while (!IsConnected()) { 227 printf("Waiting for debugger connection...\n");
227 // Busy wait. 228 dart::Monitor::WaitResult res = ml.Wait(dart::Monitor::kNoTimeout);
229 ASSERT(res == dart::Monitor::kNotified);
230 }
228 } 231 }
229 SendBreakpointEvent(bpt, trace); 232 SendBreakpointEvent(bpt, trace);
230 HandleMessages(); 233 HandleMessages();
231 if (!msgbuf_->Alive()) { 234 if (!msgbuf_->Alive()) {
232 CloseDbgConnection(); 235 CloseDbgConnection();
233 } 236 }
234 } 237 }
235 238
236 239
237 void DebuggerConnectionHandler::AcceptDbgConnection(int debugger_fd) { 240 void DebuggerConnectionHandler::AcceptDbgConnection(int debugger_fd) {
238 debugger_fd_ = debugger_fd; 241 debugger_fd_ = debugger_fd;
239 ASSERT(msgbuf_ == NULL); 242 ASSERT(msgbuf_ == NULL);
240 msgbuf_ = new MessageBuffer(debugger_fd_); 243 msgbuf_ = new MessageBuffer(debugger_fd_);
244 {
245 MonitorLocker ml(&is_connected_);
246 ml.Notify();
247 }
241 } 248 }
242 249
243 void DebuggerConnectionHandler::CloseDbgConnection() { 250 void DebuggerConnectionHandler::CloseDbgConnection() {
244 if (debugger_fd_ >= 0) { 251 if (debugger_fd_ >= 0) {
245 // TODO(hausner): need a Socket::Close() function. 252 // TODO(hausner): need a Socket::Close() function.
246 } 253 }
247 if (msgbuf_ != NULL) { 254 if (msgbuf_ != NULL) {
248 delete msgbuf_; 255 delete msgbuf_;
249 msgbuf_ = NULL; 256 msgbuf_ = NULL;
250 } 257 }
(...skipping 11 matching lines...) Expand all
262 269
263 handler_started_ = true; 270 handler_started_ = true;
264 DebuggerConnectionImpl::StartHandler(port_number); 271 DebuggerConnectionImpl::StartHandler(port_number);
265 Dart_SetBreakpointHandler(BreakpointHandler); 272 Dart_SetBreakpointHandler(BreakpointHandler);
266 } 273 }
267 274
268 275
269 DebuggerConnectionHandler::~DebuggerConnectionHandler() { 276 DebuggerConnectionHandler::~DebuggerConnectionHandler() {
270 CloseDbgConnection(); 277 CloseDbgConnection();
271 } 278 }
OLDNEW
« no previous file with comments | « runtime/bin/dbg_connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698