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

Side by Side Diff: runtime/bin/eventhandler_macos.cc

Issue 17851004: One event handler for all isolates (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove unused line. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/eventhandler_macos.h ('k') | runtime/bin/eventhandler_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 EventHandlerImplementation::EventHandlerImplementation() 123 EventHandlerImplementation::EventHandlerImplementation()
124 : socket_map_(&HashMap::SamePointerValue, 16) { 124 : socket_map_(&HashMap::SamePointerValue, 16) {
125 intptr_t result; 125 intptr_t result;
126 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); 126 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_));
127 if (result != 0) { 127 if (result != 0) {
128 FATAL("Pipe creation failed"); 128 FATAL("Pipe creation failed");
129 } 129 }
130 FDUtils::SetNonBlocking(interrupt_fds_[0]); 130 FDUtils::SetNonBlocking(interrupt_fds_[0]);
131 FDUtils::SetCloseOnExec(interrupt_fds_[0]); 131 FDUtils::SetCloseOnExec(interrupt_fds_[0]);
132 FDUtils::SetCloseOnExec(interrupt_fds_[1]); 132 FDUtils::SetCloseOnExec(interrupt_fds_[1]);
133 timeout_ = kInfinityTimeout;
134 timeout_port_ = 0;
135 shutdown_ = false; 133 shutdown_ = false;
136 134
137 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); 135 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue());
138 if (kqueue_fd_ == -1) { 136 if (kqueue_fd_ == -1) {
139 FATAL("Failed creating kqueue"); 137 FATAL("Failed creating kqueue");
140 } 138 }
141 FDUtils::SetCloseOnExec(kqueue_fd_); 139 FDUtils::SetCloseOnExec(kqueue_fd_);
142 // Register the interrupt_fd with the kqueue. 140 // Register the interrupt_fd with the kqueue.
143 struct kevent event; 141 struct kevent event;
144 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL); 142 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 total_read = total_read + bytes_read; 206 total_read = total_read + bytes_read;
209 } 207 }
210 } 208 }
211 return (total_read == kInterruptMessageSize) ? true : false; 209 return (total_read == kInterruptMessageSize) ? true : false;
212 } 210 }
213 211
214 void EventHandlerImplementation::HandleInterruptFd() { 212 void EventHandlerImplementation::HandleInterruptFd() {
215 InterruptMessage msg; 213 InterruptMessage msg;
216 while (GetInterruptMessage(&msg)) { 214 while (GetInterruptMessage(&msg)) {
217 if (msg.id == kTimerId) { 215 if (msg.id == kTimerId) {
218 timeout_ = msg.data; 216 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data);
219 timeout_port_ = msg.dart_port;
220 } else if (msg.id == kShutdownId) { 217 } else if (msg.id == kShutdownId) {
221 shutdown_ = true; 218 shutdown_ = true;
222 } else { 219 } else {
223 SocketData* sd = GetSocketData(msg.id); 220 SocketData* sd = GetSocketData(msg.id);
224 if ((msg.data & (1 << kShutdownReadCommand)) != 0) { 221 if ((msg.data & (1 << kShutdownReadCommand)) != 0) {
225 ASSERT(msg.data == (1 << kShutdownReadCommand)); 222 ASSERT(msg.data == (1 << kShutdownReadCommand));
226 // Close the socket for reading. 223 // Close the socket for reading.
227 sd->ShutdownRead(); 224 sd->ShutdownRead();
228 UpdateKqueue(kqueue_fd_, sd); 225 UpdateKqueue(kqueue_fd_, sd);
229 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { 226 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 ASSERT(port != 0); 350 ASSERT(port != 0);
354 DartUtils::PostInt32(port, event_mask); 351 DartUtils::PostInt32(port, event_mask);
355 } 352 }
356 } 353 }
357 } 354 }
358 HandleInterruptFd(); 355 HandleInterruptFd();
359 } 356 }
360 357
361 358
362 int64_t EventHandlerImplementation::GetTimeout() { 359 int64_t EventHandlerImplementation::GetTimeout() {
363 if (timeout_ == kInfinityTimeout) { 360 if (!timeout_queue_.HasTimeout()) {
364 return kInfinityTimeout; 361 return kInfinityTimeout;
365 } 362 }
366 int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); 363 int64_t millis = timeout_queue_.CurrentTimeout() -
364 TimerUtils::GetCurrentTimeMilliseconds();
367 return (millis < 0) ? 0 : millis; 365 return (millis < 0) ? 0 : millis;
368 } 366 }
369 367
370 368
371 void EventHandlerImplementation::HandleTimeout() { 369 void EventHandlerImplementation::HandleTimeout() {
372 if (timeout_ != kInfinityTimeout) { 370 if (timeout_queue_.HasTimeout()) {
373 int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); 371 int64_t millis = timeout_queue_.CurrentTimeout() -
372 TimerUtils::GetCurrentTimeMilliseconds();
374 if (millis <= 0) { 373 if (millis <= 0) {
375 DartUtils::PostNull(timeout_port_); 374 DartUtils::PostNull(timeout_queue_.CurrentPort());
376 timeout_ = kInfinityTimeout; 375 timeout_queue_.RemoveCurrent();
377 timeout_port_ = 0;
378 } 376 }
379 } 377 }
380 } 378 }
381 379
382 380
383 void EventHandlerImplementation::EventHandlerEntry(uword args) { 381 void EventHandlerImplementation::EventHandlerEntry(uword args) {
384 static const intptr_t kMaxEvents = 16; 382 static const intptr_t kMaxEvents = 16;
385 struct kevent events[kMaxEvents]; 383 struct kevent events[kMaxEvents];
386 EventHandler* handler = reinterpret_cast<EventHandler*>(args); 384 EventHandler* handler = reinterpret_cast<EventHandler*>(args);
387 EventHandlerImplementation* handler_impl = &handler->delegate_; 385 EventHandlerImplementation* handler_impl = &handler->delegate_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 444
447 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 445 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
448 // The hashmap does not support keys with value 0. 446 // The hashmap does not support keys with value 0.
449 return dart::Utils::WordHash(fd + 1); 447 return dart::Utils::WordHash(fd + 1);
450 } 448 }
451 449
452 } // namespace bin 450 } // namespace bin
453 } // namespace dart 451 } // namespace dart
454 452
455 #endif // defined(TARGET_OS_MACOS) 453 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_macos.h ('k') | runtime/bin/eventhandler_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698