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

Side by Side Diff: runtime/bin/eventhandler_android.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
« no previous file with comments | « no previous file | runtime/bin/eventhandler_linux.cc » ('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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
77 // Only report events once and wait for them to be re-enabled after the
78 // event has been handled by the Dart code.
79 event.events |= EPOLLONESHOT;
zra 2013/11/22 22:30:58 Is this used only in the standalone VM? It isn't b
77 int status = 0; 80 int status = 0;
78 if (sd->tracked_by_epoll()) { 81 if (sd->tracked_by_epoll()) {
79 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 82 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
80 EPOLL_CTL_MOD, 83 EPOLL_CTL_MOD,
81 sd->fd(), 84 sd->fd(),
82 &event)); 85 &event));
83 } else { 86 } else {
84 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 87 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
85 EPOLL_CTL_ADD, 88 EPOLL_CTL_ADD,
86 sd->fd(), 89 sd->fd(),
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 338 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
336 int size) { 339 int size) {
337 bool interrupt_seen = false; 340 bool interrupt_seen = false;
338 for (int i = 0; i < size; i++) { 341 for (int i = 0; i < size; i++) {
339 if (events[i].data.ptr == NULL) { 342 if (events[i].data.ptr == NULL) {
340 interrupt_seen = true; 343 interrupt_seen = true;
341 } else { 344 } else {
342 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); 345 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
343 intptr_t event_mask = GetPollEvents(events[i].events, sd); 346 intptr_t event_mask = GetPollEvents(events[i].events, sd);
344 if (event_mask != 0) { 347 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(); 348 Dart_Port port = sd->port();
350 ASSERT(port != 0); 349 ASSERT(port != 0);
351 DartUtils::PostInt32(port, event_mask); 350 DartUtils::PostInt32(port, event_mask);
352 } 351 }
353 } 352 }
354 } 353 }
355 if (interrupt_seen) { 354 if (interrupt_seen) {
356 // Handle after socket events, so we avoid closing a socket before we handle 355 // Handle after socket events, so we avoid closing a socket before we handle
357 // the current events. 356 // the current events.
358 HandleInterruptFd(); 357 HandleInterruptFd();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (millis > kMaxInt32) millis = kMaxInt32; 393 if (millis > kMaxInt32) millis = kMaxInt32;
395 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_, 394 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_,
396 events, 395 events,
397 kMaxEvents, 396 kMaxEvents,
398 millis)); 397 millis));
399 ASSERT(EAGAIN == EWOULDBLOCK); 398 ASSERT(EAGAIN == EWOULDBLOCK);
400 if (result == -1) { 399 if (result == -1) {
401 if (errno != EWOULDBLOCK) { 400 if (errno != EWOULDBLOCK) {
402 perror("Poll failed"); 401 perror("Poll failed");
403 } 402 }
403 } else if (result == 0) {
404 handler->HandleTimeout();
404 } else { 405 } else {
405 handler->HandleTimeout();
406 handler->HandleEvents(events, result); 406 handler->HandleEvents(events, result);
407 } 407 }
408 } 408 }
409 } 409 }
410 410
411 411
412 void EventHandlerImplementation::Start(EventHandler* handler) { 412 void EventHandlerImplementation::Start(EventHandler* handler) {
413 int result = dart::Thread::Start(&EventHandlerImplementation::Poll, 413 int result = dart::Thread::Start(&EventHandlerImplementation::Poll,
414 reinterpret_cast<uword>(handler)); 414 reinterpret_cast<uword>(handler));
415 if (result != 0) { 415 if (result != 0) {
(...skipping 22 matching lines...) Expand all
438 438
439 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 439 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
440 // The hashmap does not support keys with value 0. 440 // The hashmap does not support keys with value 0.
441 return dart::Utils::WordHash(fd + 1); 441 return dart::Utils::WordHash(fd + 1);
442 } 442 }
443 443
444 } // namespace bin 444 } // namespace bin
445 } // namespace dart 445 } // namespace dart
446 446
447 #endif // defined(TARGET_OS_ANDROID) 447 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698