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

Side by Side Diff: runtime/bin/eventhandler_linux.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: 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
« no previous file with comments | « no previous file | no next file » | 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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 } 67 }
68 68
69 69
70 // Register the file descriptor for a SocketData structure with epoll 70 // Register the file descriptor for a SocketData structure with epoll
71 // if events are requested. 71 // if events are requested.
72 static void UpdateEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 72 static void UpdateEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
73 struct epoll_event event; 73 struct epoll_event event;
74 event.events = sd->GetPollEvents(); 74 event.events = sd->GetPollEvents();
75 event.data.ptr = sd; 75 event.data.ptr = sd;
76 if (sd->port() != 0 && event.events != 0) { 76 if (sd->port() != 0 && event.events != 0) {
Søren Gjesse 2013/11/22 07:38:56 Please add a comment here. "Only report events onc
Anders Johnsen 2013/11/22 07:48:34 Done.
77 event.events |= EPOLLONESHOT;
Søren Gjesse 2013/11/22 07:38:56 Please open a bug on checking whether this is poss
Anders Johnsen 2013/11/22 07:48:34 Added mac and android versions too.
77 int status = 0; 78 int status = 0;
78 if (sd->tracked_by_epoll()) { 79 if (sd->tracked_by_epoll()) {
79 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 80 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
80 EPOLL_CTL_MOD, 81 EPOLL_CTL_MOD,
81 sd->fd(), 82 sd->fd(),
82 &event)); 83 &event));
83 } else { 84 } else {
84 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 85 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
85 EPOLL_CTL_ADD, 86 EPOLL_CTL_ADD,
86 sd->fd(), 87 sd->fd(),
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 336 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
336 int size) { 337 int size) {
337 bool interrupt_seen = false; 338 bool interrupt_seen = false;
338 for (int i = 0; i < size; i++) { 339 for (int i = 0; i < size; i++) {
339 if (events[i].data.ptr == NULL) { 340 if (events[i].data.ptr == NULL) {
340 interrupt_seen = true; 341 interrupt_seen = true;
341 } else { 342 } else {
342 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); 343 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
343 intptr_t event_mask = GetPollEvents(events[i].events, sd); 344 intptr_t event_mask = GetPollEvents(events[i].events, sd);
344 if (event_mask != 0) { 345 if (event_mask != 0) {
345 // Unregister events for the file descriptor. Events will be
346 // registered again when the current event has been handled in
347 // Dart code.
348 RemoveFromEpollInstance(epoll_fd_, sd);
349 Dart_Port port = sd->port(); 346 Dart_Port port = sd->port();
350 ASSERT(port != 0); 347 ASSERT(port != 0);
351 DartUtils::PostInt32(port, event_mask); 348 DartUtils::PostInt32(port, event_mask);
352 } 349 }
353 } 350 }
354 } 351 }
355 if (interrupt_seen) { 352 if (interrupt_seen) {
356 // Handle after socket events, so we avoid closing a socket before we handle 353 // Handle after socket events, so we avoid closing a socket before we handle
357 // the current events. 354 // the current events.
358 HandleInterruptFd(); 355 HandleInterruptFd();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (millis > kMaxInt32) millis = kMaxInt32; 392 if (millis > kMaxInt32) millis = kMaxInt32;
396 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_, 393 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_,
397 events, 394 events,
398 kMaxEvents, 395 kMaxEvents,
399 millis)); 396 millis));
400 ASSERT(EAGAIN == EWOULDBLOCK); 397 ASSERT(EAGAIN == EWOULDBLOCK);
401 if (result == -1) { 398 if (result == -1) {
402 if (errno != EWOULDBLOCK) { 399 if (errno != EWOULDBLOCK) {
403 perror("Poll failed"); 400 perror("Poll failed");
404 } 401 }
402 } else if (result == 0) {
403 handler_impl->HandleTimeout();
405 } else { 404 } else {
406 handler_impl->HandleTimeout();
407 handler_impl->HandleEvents(events, result); 405 handler_impl->HandleEvents(events, result);
408 } 406 }
409 } 407 }
410 delete handler; 408 delete handler;
411 } 409 }
412 410
413 411
414 void EventHandlerImplementation::Start(EventHandler* handler) { 412 void EventHandlerImplementation::Start(EventHandler* handler) {
415 int result = dart::Thread::Start(&EventHandlerImplementation::Poll, 413 int result = dart::Thread::Start(&EventHandlerImplementation::Poll,
416 reinterpret_cast<uword>(handler)); 414 reinterpret_cast<uword>(handler));
(...skipping 23 matching lines...) Expand all
440 438
441 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 439 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
442 // The hashmap does not support keys with value 0. 440 // The hashmap does not support keys with value 0.
443 return dart::Utils::WordHash(fd + 1); 441 return dart::Utils::WordHash(fd + 1);
444 } 442 }
445 443
446 } // namespace bin 444 } // namespace bin
447 } // namespace dart 445 } // namespace dart
448 446
449 #endif // defined(TARGET_OS_LINUX) 447 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698