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

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

Issue 82873002: Limit the number of syscalls made by the Eventhandler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mac fix. Created 7 years 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
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 } 72 }
73 73
74 74
75 // Update the kqueue registration for SocketData structure to reflect 75 // Update the kqueue registration for SocketData structure to reflect
76 // the events currently of interest. 76 // the events currently of interest.
77 static void UpdateKqueue(intptr_t kqueue_fd_, SocketData* sd) { 77 static void UpdateKqueue(intptr_t kqueue_fd_, SocketData* sd) {
78 static const intptr_t kMaxChanges = 2; 78 static const intptr_t kMaxChanges = 2;
79 intptr_t changes = 0; 79 intptr_t changes = 0;
80 struct kevent events[kMaxChanges]; 80 struct kevent events[kMaxChanges];
81 // Only report events once and wait for them to be re-enabled after the
82 // event has been handled by the Dart code. This is done by using EV_ONESHOT.
81 if (sd->port() != 0) { 83 if (sd->port() != 0) {
82 // Register or unregister READ filter if needed. 84 // Register or unregister READ filter if needed.
83 if (sd->HasReadEvent()) { 85 if (sd->HasReadEvent()) {
84 if (!sd->read_tracked_by_kqueue()) { 86 if (!sd->read_tracked_by_kqueue()) {
85 EV_SET(events + changes, sd->fd(), EVFILT_READ, EV_ADD, 0, 0, sd); 87 EV_SET(events + changes,
88 sd->fd(),
89 EVFILT_READ,
90 EV_ADD | EV_ONESHOT,
91 0,
92 0,
93 sd);
86 ++changes; 94 ++changes;
87 sd->set_read_tracked_by_kqueue(true); 95 sd->set_read_tracked_by_kqueue(true);
88 } 96 }
89 } else if (sd->read_tracked_by_kqueue()) { 97 } else if (sd->read_tracked_by_kqueue()) {
90 EV_SET(events + changes, sd->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL); 98 EV_SET(events + changes, sd->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
91 ++changes; 99 ++changes;
92 sd->set_read_tracked_by_kqueue(false); 100 sd->set_read_tracked_by_kqueue(false);
93 } 101 }
94 // Register or unregister WRITE filter if needed. 102 // Register or unregister WRITE filter if needed.
95 if (sd->HasWriteEvent()) { 103 if (sd->HasWriteEvent()) {
96 if (!sd->write_tracked_by_kqueue()) { 104 if (!sd->write_tracked_by_kqueue()) {
97 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_ADD, 0, 0, sd); 105 EV_SET(events + changes,
106 sd->fd(),
107 EVFILT_WRITE,
108 EV_ADD | EV_ONESHOT,
109 0,
110 0,
111 sd);
98 ++changes; 112 ++changes;
99 sd->set_write_tracked_by_kqueue(true); 113 sd->set_write_tracked_by_kqueue(true);
100 } 114 }
101 } else if (sd->write_tracked_by_kqueue()) { 115 } else if (sd->write_tracked_by_kqueue()) {
102 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); 116 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
103 ++changes; 117 ++changes;
104 sd->set_write_tracked_by_kqueue(false); 118 sd->set_write_tracked_by_kqueue(false);
105 } 119 }
106 } 120 }
107 if (changes > 0) { 121 if (changes > 0) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if ((events[i].flags & EV_ERROR) != 0) { 349 if ((events[i].flags & EV_ERROR) != 0) {
336 const int kBufferSize = 1024; 350 const int kBufferSize = 1024;
337 char error_message[kBufferSize]; 351 char error_message[kBufferSize];
338 strerror_r(events[i].data, error_message, kBufferSize); 352 strerror_r(events[i].data, error_message, kBufferSize);
339 FATAL1("kevent failed %s\n", error_message); 353 FATAL1("kevent failed %s\n", error_message);
340 } 354 }
341 if (events[i].udata == NULL) { 355 if (events[i].udata == NULL) {
342 interrupt_seen = true; 356 interrupt_seen = true;
343 } else { 357 } else {
344 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata); 358 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata);
359 sd->set_read_tracked_by_kqueue(false);
360 sd->set_write_tracked_by_kqueue(false);
345 intptr_t event_mask = GetEvents(events + i, sd); 361 intptr_t event_mask = GetEvents(events + i, sd);
346 if (event_mask != 0) { 362 if (event_mask != 0) {
347 // Unregister events for the file descriptor. Events will be
348 // registered again when the current event has been handled in
349 // Dart code.
350 RemoveFromKqueue(kqueue_fd_, sd);
351 Dart_Port port = sd->port(); 363 Dart_Port port = sd->port();
352 ASSERT(port != 0); 364 ASSERT(port != 0);
353 DartUtils::PostInt32(port, event_mask); 365 DartUtils::PostInt32(port, event_mask);
354 } 366 }
355 } 367 }
356 } 368 }
357 if (interrupt_seen) { 369 if (interrupt_seen) {
358 // Handle after socket events, so we avoid closing a socket before we handle 370 // Handle after socket events, so we avoid closing a socket before we handle
359 // the current events. 371 // the current events.
360 HandleInterruptFd(); 372 HandleInterruptFd();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 465
454 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 466 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
455 // The hashmap does not support keys with value 0. 467 // The hashmap does not support keys with value 0.
456 return dart::Utils::WordHash(fd + 1); 468 return dart::Utils::WordHash(fd + 1);
457 } 469 }
458 470
459 } // namespace bin 471 } // namespace bin
460 } // namespace dart 472 } // namespace dart
461 473
462 #endif // defined(TARGET_OS_MACOS) 474 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« runtime/bin/eventhandler_android.cc ('K') | « runtime/bin/eventhandler_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698