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

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

Issue 1291163002: Join embeder threads on Windows. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/bin/dbg_connection_win.h ('k') | runtime/bin/eventhandler_win.h » ('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 (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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/dbg_connection.h" 8 #include "bin/dbg_connection.h"
9 9
10 #include "bin/eventhandler.h" 10 #include "bin/eventhandler.h"
11 11 #include "bin/lockers.h"
12 #include "bin/log.h"
13 #include "bin/thread.h"
12 14
13 namespace dart { 15 namespace dart {
14 namespace bin { 16 namespace bin {
15 17
18 Monitor* DebuggerConnectionImpl::handler_monitor_ = new Monitor();
19 ThreadId DebuggerConnectionImpl::handler_thread_id_ = Thread::kInvalidThreadId;
20 bool DebuggerConnectionImpl::handler_thread_running_ = false;
21
22
23 void DebuggerConnectionImpl::NotifyThreadStarted() {
24 MonitorLocker ml(handler_monitor_);
25 ASSERT(!handler_thread_running_);
26 ASSERT(handler_thread_id_ == Thread::kInvalidThreadId);
27 handler_thread_running_ = true;
28 handler_thread_id_ = Thread::GetCurrentThreadId();
29 ml.Notify();
30 }
31
32
33 void DebuggerConnectionImpl::WaitForThreadStarted() {
34 MonitorLocker ml(handler_monitor_);
35 while (!handler_thread_running_) {
36 ml.Wait();
37 }
38 ASSERT(handler_thread_id_ != Thread::kInvalidThreadId);
39 }
40
41
42 void DebuggerConnectionImpl::NotifyThreadFinished() {
43 MonitorLocker ml(handler_monitor_);
44 ASSERT(handler_thread_running_);
45 ASSERT(handler_thread_id_ != Thread::kInvalidThreadId);
46 handler_thread_running_ = false;
47 ml.Notify();
48 }
49
50
51 void DebuggerConnectionImpl::WaitForThreadFinished() {
52 MonitorLocker ml(handler_monitor_);
53 while (handler_thread_running_) {
54 ml.Wait();
55 }
56 ASSERT(handler_thread_id_ != Thread::kInvalidThreadId);
57 Thread::Join(handler_thread_id_);
58 handler_thread_id_ = Thread::kInvalidThreadId;
59 }
60
61
16 void DebuggerConnectionImpl::ThreadEntry(uword args) { 62 void DebuggerConnectionImpl::ThreadEntry(uword args) {
63 NotifyThreadStarted();
17 ListenSocket* listen_socket = 64 ListenSocket* listen_socket =
18 reinterpret_cast<ListenSocket*>(DebuggerConnectionHandler::listener_fd_); 65 reinterpret_cast<ListenSocket*>(DebuggerConnectionHandler::listener_fd_);
19 SOCKET client_socket = accept(listen_socket->socket(), NULL, NULL); 66 SOCKET client_socket = accept(listen_socket->socket(), NULL, NULL);
20 if (client_socket == INVALID_SOCKET) { 67 if (client_socket == INVALID_SOCKET) {
21 FATAL("Accepting new debugger connection failed.\n"); 68 FATAL("Accepting new debugger connection failed.\n");
22 } 69 }
23 ClientSocket* socket = new ClientSocket(client_socket); 70 ClientSocket* socket = new ClientSocket(client_socket);
24 DebuggerConnectionHandler::AcceptDbgConnection( 71 DebuggerConnectionHandler::AcceptDbgConnection(
25 reinterpret_cast<intptr_t>(socket)); 72 reinterpret_cast<intptr_t>(socket));
73 NotifyThreadFinished();
26 } 74 }
27 75
28 76
29 void DebuggerConnectionImpl::StartHandler(int port_number) { 77 void DebuggerConnectionImpl::StartHandler(int port_number) {
30 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1); 78 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1);
31 int result = Thread::Start(&DebuggerConnectionImpl::ThreadEntry, 0); 79 int result = Thread::Start(&DebuggerConnectionImpl::ThreadEntry, 0);
32 if (result != 0) { 80 if (result != 0) {
33 FATAL1("Failed to start debugger connection handler thread: %d\n", result); 81 FATAL1("Failed to start debugger connection handler thread: %d\n", result);
34 } 82 }
83 WaitForThreadStarted();
35 } 84 }
36 85
37 86
87 void DebuggerConnectionImpl::StopHandler(intptr_t debug_fd) {
88 Send(debug_fd, NULL, 0);
89 WaitForThreadFinished();
90 }
91
92
38 intptr_t DebuggerConnectionImpl::Send(intptr_t socket, 93 intptr_t DebuggerConnectionImpl::Send(intptr_t socket,
39 const char* buf, 94 const char* buf,
40 int len) { 95 int len) {
41 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(socket); 96 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(socket);
42 return send(client_socket->socket(), buf, len, 0); 97 return send(client_socket->socket(), buf, len, 0);
43 } 98 }
44 99
45 100
46 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) { 101 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) {
47 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(socket); 102 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(socket);
48 return recv(client_socket->socket(), buf, len, 0); 103 return recv(client_socket->socket(), buf, len, 0);
49 } 104 }
50 105
51 } // namespace bin 106 } // namespace bin
52 } // namespace dart 107 } // namespace dart
53 108
54 #endif // defined(TARGET_OS_WINDOWS) 109 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/dbg_connection_win.h ('k') | runtime/bin/eventhandler_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698