Index: runtime/bin/eventhandler_macos.cc |
diff --git a/runtime/bin/eventhandler_macos.cc b/runtime/bin/eventhandler_macos.cc |
index 4166ce05f160871ba0a3ffd7a3c483f1898eb6c2..604246fadb03323c18bdd4427e88024d5162c187 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 (true) { |
intptr_t millis = handler->GetTimeout(); |
// NULL pointer timespec for infinite timeout. |
ASSERT(kInfinityTimeout < 0); |
@@ -380,6 +384,7 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) { |
handler->HandleTimeout(); |
handler->HandleEvents(events, result); |
} |
+ if (handler->shutdown_) break; |
} |
} |
@@ -394,6 +399,11 @@ void EventHandlerImplementation::StartEventHandler() { |
} |
+void EventHandlerImplementation::Shutdown() { |
+ SendData(kShutdownId, 0, 0); |
+} |
+ |
+ |
void EventHandlerImplementation::SendData(intptr_t id, |
Dart_Port dart_port, |
intptr_t data) { |