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

Unified Diff: src/vm/event_handler_macos.cc

Issue 1375373004: Use the event-handler for timers. (Closed) Base URL: git@github.com:dart-lang/fletch.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/vm/event_handler_linux.cc ('k') | src/vm/event_handler_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/vm/event_handler_macos.cc
diff --git a/src/vm/event_handler_macos.cc b/src/vm/event_handler_macos.cc
index 41f8112e0deb6000e30534e3180af5b059afc11c..335731451ae4c6ac0142ba431180600e42acd388 100644
--- a/src/vm/event_handler_macos.cc
+++ b/src/vm/event_handler_macos.cc
@@ -8,6 +8,7 @@
#include <sys/event.h>
#include <sys/types.h>
+#include <time.h>
#include <unistd.h>
#include "src/vm/thread.h"
@@ -25,21 +26,48 @@ void EventHandler::Run() {
event.filter = EVFILT_READ;
kevent(fd_, &event, 1, NULL, 0, NULL);
while (true) {
- int status = kevent(fd_, NULL, 0, &event, 1, NULL);
- if (status != 1) continue;
-
- if (event.ident == static_cast<uintptr_t>(read_fd_)) {
- close(read_fd_);
- close(fd_);
+ int64 next_timeout;
+ {
ScopedMonitorLock locker(monitor_);
- fd_ = -1;
- monitor_->Notify();
- return;
+ next_timeout = next_timeout_;
+ }
+
+ timespec ts;
+ timespec* interval = NULL;
+
+ if (next_timeout != INT64_MAX) {
+ next_timeout -= Platform::GetMicroseconds() / 1000;
+ if (next_timeout < 0) next_timeout = 0;
+ ts.tv_sec = next_timeout / 1000;
+ ts.tv_nsec = (next_timeout % 1000) * 1000000;
+ interval = &ts;
}
+ int status = kevent(fd_, NULL, 0, &event, 1, interval);
+
+ HandleTimeouts();
+
+ if (status != 1) continue;
+
int filter = event.filter;
int flags = event.flags;
int fflags = event.fflags;
+
+ if (event.ident == static_cast<uintptr_t>(read_fd_)) {
+ if ((flags & EV_EOF) == 0) {
+ char b;
+ read(read_fd_, &b, 1);
+ continue;
+ } else {
+ close(read_fd_);
+ close(fd_);
+ ScopedMonitorLock locker(monitor_);
+ fd_ = -1;
+ monitor_->Notify();
+ return;
+ }
+ }
+
word mask = 0;
if (filter == EVFILT_READ) {
mask = READ_EVENT;
« no previous file with comments | « src/vm/event_handler_linux.cc ('k') | src/vm/event_handler_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698