Index: runtime/bin/eventhandler_macos.cc |
diff --git a/runtime/bin/eventhandler_macos.cc b/runtime/bin/eventhandler_macos.cc |
index 826e6000341e1f90adbec778f8d673490cf707e1..9a60d6f0037e547f891872d35dc1c3a363639862 100644 |
--- a/runtime/bin/eventhandler_macos.cc |
+++ b/runtime/bin/eventhandler_macos.cc |
@@ -130,8 +130,6 @@ EventHandlerImplementation::EventHandlerImplementation() |
FDUtils::SetNonBlocking(interrupt_fds_[0]); |
FDUtils::SetCloseOnExec(interrupt_fds_[0]); |
FDUtils::SetCloseOnExec(interrupt_fds_[1]); |
- timeout_ = kInfinityTimeout; |
- timeout_port_ = 0; |
shutdown_ = false; |
kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); |
@@ -215,8 +213,7 @@ void EventHandlerImplementation::HandleInterruptFd() { |
InterruptMessage msg; |
while (GetInterruptMessage(&msg)) { |
if (msg.id == kTimerId) { |
- timeout_ = msg.data; |
- timeout_port_ = msg.dart_port; |
+ timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); |
} else if (msg.id == kShutdownId) { |
shutdown_ = true; |
} else { |
@@ -360,21 +357,22 @@ void EventHandlerImplementation::HandleEvents(struct kevent* events, |
int64_t EventHandlerImplementation::GetTimeout() { |
- if (timeout_ == kInfinityTimeout) { |
+ if (!timeout_queue_.HasTimeout()) { |
return kInfinityTimeout; |
} |
- int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
+ int64_t millis = timeout_queue_.CurrentTimeout() - |
+ TimerUtils::GetCurrentTimeMilliseconds(); |
return (millis < 0) ? 0 : millis; |
} |
void EventHandlerImplementation::HandleTimeout() { |
- if (timeout_ != kInfinityTimeout) { |
- int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
+ if (timeout_queue_.HasTimeout()) { |
+ int64_t millis = timeout_queue_.CurrentTimeout() - |
+ TimerUtils::GetCurrentTimeMilliseconds(); |
if (millis <= 0) { |
- DartUtils::PostNull(timeout_port_); |
- timeout_ = kInfinityTimeout; |
- timeout_port_ = 0; |
+ DartUtils::PostNull(timeout_queue_.CurrentPort()); |
+ timeout_queue_.RemoveCurrent(); |
} |
} |
} |