Index: runtime/bin/eventhandler_macos.cc |
diff --git a/runtime/bin/eventhandler_macos.cc b/runtime/bin/eventhandler_macos.cc |
index 4166ce05f160871ba0a3ffd7a3c483f1898eb6c2..22c80eceb5393114bff3a4be7bf80f0f7868049e 100644 |
--- a/runtime/bin/eventhandler_macos.cc |
+++ b/runtime/bin/eventhandler_macos.cc |
@@ -32,6 +32,7 @@ int64_t GetCurrentTimeMilliseconds() { |
static const int kInterruptMessageSize = sizeof(InterruptMessage); |
static const int kInfinityTimeout = -1; |
static const int kTimerId = -1; |
+static const int kShutdownId = -2; |
bool SocketData::HasReadEvent() { |
@@ -123,6 +124,7 @@ EventHandlerImplementation::EventHandlerImplementation() |
FDUtils::SetNonBlocking(interrupt_fds_[0]); |
timeout_ = kInfinityTimeout; |
timeout_port_ = 0; |
+ shutdown_ = false; |
kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); |
if (kqueue_fd_ == -1) { |
@@ -205,6 +207,8 @@ void EventHandlerImplementation::HandleInterruptFd() { |
if (msg.id == kTimerId) { |
timeout_ = msg.data; |
timeout_port_ = msg.dart_port; |
+ } else if (msg.id == kShutdownId) { |
+ shutdown_ = true; |
} else { |
SocketData* sd = GetSocketData(msg.id); |
if ((msg.data & (1 << kShutdownReadCommand)) != 0) { |
@@ -357,7 +361,7 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) { |
EventHandlerImplementation* handler = |
reinterpret_cast<EventHandlerImplementation*>(args); |
ASSERT(handler != NULL); |
- while (1) { |
+ while (!handler->shutdown_) { |
intptr_t millis = handler->GetTimeout(); |
// NULL pointer timespec for infinite timeout. |
ASSERT(kInfinityTimeout < 0); |
@@ -384,7 +388,7 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) { |
} |
-void EventHandlerImplementation::StartEventHandler() { |
+void EventHandlerImplementation::Start() { |
int result = |
dart::Thread::Start(&EventHandlerImplementation::EventHandlerEntry, |
reinterpret_cast<uword>(this)); |
@@ -394,6 +398,11 @@ void EventHandlerImplementation::StartEventHandler() { |
} |
+void EventHandlerImplementation::Shutdown() { |
+ SendData(kShutdownId, 0, 0); |
+} |
+ |
+ |
void EventHandlerImplementation::SendData(intptr_t id, |
Dart_Port dart_port, |
intptr_t data) { |