Index: runtime/bin/eventhandler_linux.cc |
diff --git a/runtime/bin/eventhandler_linux.cc b/runtime/bin/eventhandler_linux.cc |
index e15f3dfd6b39da908c9552a7d124fdb07547d7e3..6b0a70b7a065261d390540a2af96ebabbfbf8f1b 100644 |
--- a/runtime/bin/eventhandler_linux.cc |
+++ b/runtime/bin/eventhandler_linux.cc |
@@ -33,6 +33,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; |
intptr_t SocketData::GetPollEvents() { |
@@ -105,6 +106,7 @@ EventHandlerImplementation::EventHandlerImplementation() |
FDUtils::SetNonBlocking(interrupt_fds_[0]); |
timeout_ = kInfinityTimeout; |
timeout_port_ = 0; |
+ shutdown_ = false; |
// The initial size passed to epoll_create is ignore on newer (>= |
// 2.6.8) Linux versions |
static const int kEpollInitialSize = 64; |
@@ -193,6 +195,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) { |
@@ -373,7 +377,7 @@ void EventHandlerImplementation::Poll(uword args) { |
EventHandlerImplementation* handler = |
reinterpret_cast<EventHandlerImplementation*>(args); |
ASSERT(handler != NULL); |
- while (1) { |
+ while (true) { |
Søren Gjesse
2012/06/29 11:54:11
Maybe "while (!handler->shutdown_)" here and no ne
Mads Ager (google)
2012/06/29 14:30:24
Absolutely! Thanks for catching that.
|
intptr_t millis = handler->GetTimeout(); |
intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_, |
events, |
@@ -388,6 +392,7 @@ void EventHandlerImplementation::Poll(uword args) { |
handler->HandleTimeout(); |
handler->HandleEvents(events, result); |
} |
+ if (handler->shutdown_) break; |
} |
} |
@@ -401,6 +406,11 @@ void EventHandlerImplementation::StartEventHandler() { |
} |
+void EventHandlerImplementation::Shutdown() { |
+ SendData(kShutdownId, 0, 0); |
+} |
+ |
+ |
void EventHandlerImplementation::SendData(intptr_t id, |
Dart_Port dart_port, |
intptr_t data) { |