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

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

Issue 83963003: Removes EPOLLONESHOT from Android eventhandler. (Closed) Base URL: http://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_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;
80 int status = 0; 77 int status = 0;
81 if (sd->tracked_by_epoll()) { 78 if (sd->tracked_by_epoll()) {
82 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 79 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
83 EPOLL_CTL_MOD, 80 EPOLL_CTL_MOD,
84 sd->fd(), 81 sd->fd(),
85 &event)); 82 &event));
86 } else { 83 } else {
87 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 84 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
88 EPOLL_CTL_ADD, 85 EPOLL_CTL_ADD,
89 sd->fd(), 86 sd->fd(),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (result != kInterruptMessageSize) { 169 if (result != kInterruptMessageSize) {
173 if (result == -1) { 170 if (result == -1) {
174 perror("Interrupt message failure:"); 171 perror("Interrupt message failure:");
175 } 172 }
176 FATAL1("Interrupt message failure. Wrote %d bytes.", result); 173 FATAL1("Interrupt message failure. Wrote %d bytes.", result);
177 } 174 }
178 } 175 }
179 176
180 177
181 void EventHandlerImplementation::HandleInterruptFd() { 178 void EventHandlerImplementation::HandleInterruptFd() {
182 const intptr_t MAX_MESSAGES = kInterruptMessageSize; 179 InterruptMessage msg;
Ivan Posva 2013/11/22 23:38:25 As discussed I don't think these changes had anyth
183 InterruptMessage msg[MAX_MESSAGES]; 180 intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]);
184 ssize_t bytes = TEMP_FAILURE_RETRY( 181 for (int i = 0;
185 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); 182 i + kInterruptMessageSize <= available;
186 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { 183 i += kInterruptMessageSize) {
187 if (msg[i].id == kTimerId) { 184 VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0],
188 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); 185 reinterpret_cast<char*>(&msg),
189 } else if (msg[i].id == kShutdownId) { 186 kInterruptMessageSize));
187 if (msg.id == kTimerId) {
188 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data);
189 } else if (msg.id == kShutdownId) {
190 shutdown_ = true; 190 shutdown_ = true;
191 } else { 191 } else {
192 SocketData* sd = GetSocketData(msg[i].id); 192 SocketData* sd = GetSocketData(msg.id);
193 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) { 193 if ((msg.data & (1 << kShutdownReadCommand)) != 0) {
194 ASSERT(msg[i].data == (1 << kShutdownReadCommand)); 194 ASSERT(msg.data == (1 << kShutdownReadCommand));
195 // Close the socket for reading. 195 // Close the socket for reading.
196 sd->ShutdownRead(); 196 sd->ShutdownRead();
197 UpdateEpollInstance(epoll_fd_, sd); 197 UpdateEpollInstance(epoll_fd_, sd);
198 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) { 198 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) {
199 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); 199 ASSERT(msg.data == (1 << kShutdownWriteCommand));
200 // Close the socket for writing. 200 // Close the socket for writing.
201 sd->ShutdownWrite(); 201 sd->ShutdownWrite();
202 UpdateEpollInstance(epoll_fd_, sd); 202 UpdateEpollInstance(epoll_fd_, sd);
203 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { 203 } else if ((msg.data & (1 << kCloseCommand)) != 0) {
204 ASSERT(msg[i].data == (1 << kCloseCommand)); 204 ASSERT(msg.data == (1 << kCloseCommand));
205 // Close the socket and free system resources and move on to 205 // Close the socket and free system resources and move on to
206 // next message. 206 // next message.
207 RemoveFromEpollInstance(epoll_fd_, sd); 207 RemoveFromEpollInstance(epoll_fd_, sd);
208 intptr_t fd = sd->fd(); 208 intptr_t fd = sd->fd();
209 if (fd == STDOUT_FILENO) { 209 if (fd == STDOUT_FILENO) {
210 // If stdout, redirect fd to /dev/null. 210 // If stdout, redirect fd to /dev/null.
211 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 211 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
212 ASSERT(null_fd >= 0); 212 ASSERT(null_fd >= 0);
213 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); 213 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO));
214 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 214 VOID_TEMP_FAILURE_RETRY(close(null_fd));
215 } else { 215 } else {
216 sd->Close(); 216 sd->Close();
217 } 217 }
218 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 218 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
219 delete sd; 219 delete sd;
220 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); 220 DartUtils::PostInt32(msg.dart_port, 1 << kDestroyedEvent);
221 } else { 221 } else {
222 // Setup events to wait for. 222 // Setup events to wait for.
223 sd->SetPortAndMask(msg[i].dart_port, msg[i].data); 223 sd->SetPortAndMask(msg.dart_port, msg.data);
224 UpdateEpollInstance(epoll_fd_, sd); 224 UpdateEpollInstance(epoll_fd_, sd);
225 } 225 }
226 } 226 }
227 } 227 }
228 } 228 }
229 229
230 #ifdef DEBUG_POLL 230 #ifdef DEBUG_POLL
231 static void PrintEventMask(intptr_t fd, intptr_t events) { 231 static void PrintEventMask(intptr_t fd, intptr_t events) {
232 Log::Print("%d ", fd); 232 Log::Print("%d ", fd);
233 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); 233 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 334
335 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 335 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
336 int size) { 336 int size) {
337 bool interrupt_seen = false; 337 bool interrupt_seen = false;
338 for (int i = 0; i < size; i++) { 338 for (int i = 0; i < size; i++) {
339 if (events[i].data.ptr == NULL) { 339 if (events[i].data.ptr == NULL) {
340 interrupt_seen = true; 340 interrupt_seen = true;
341 } else { 341 } else {
342 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); 342 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
343 intptr_t event_mask = GetPollEvents(events[i].events, sd); 343 intptr_t event_mask = GetPollEvents(events[i].events, sd);
344 if (event_mask == 0) { 344 if (event_mask != 0) {
345 // Event not handled, re-add to epoll. 345 // Unregister events for the file descriptor. Events will be
346 UpdateEpollInstance(epoll_fd_, sd); 346 // registered again when the current event has been handled in
347 } else { 347 // Dart code.
348 RemoveFromEpollInstance(epoll_fd_, sd);
348 Dart_Port port = sd->port(); 349 Dart_Port port = sd->port();
349 ASSERT(port != 0); 350 ASSERT(port != 0);
350 DartUtils::PostInt32(port, event_mask); 351 DartUtils::PostInt32(port, event_mask);
351 } 352 }
352 } 353 }
353 } 354 }
354 if (interrupt_seen) { 355 if (interrupt_seen) {
355 // Handle after socket events, so we avoid closing a socket before we handle 356 // Handle after socket events, so we avoid closing a socket before we handle
356 // the current events. 357 // the current events.
357 HandleInterruptFd(); 358 HandleInterruptFd();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (millis > kMaxInt32) millis = kMaxInt32; 394 if (millis > kMaxInt32) millis = kMaxInt32;
394 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_, 395 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_,
395 events, 396 events,
396 kMaxEvents, 397 kMaxEvents,
397 millis)); 398 millis));
398 ASSERT(EAGAIN == EWOULDBLOCK); 399 ASSERT(EAGAIN == EWOULDBLOCK);
399 if (result == -1) { 400 if (result == -1) {
400 if (errno != EWOULDBLOCK) { 401 if (errno != EWOULDBLOCK) {
401 perror("Poll failed"); 402 perror("Poll failed");
402 } 403 }
403 } else if (result == 0) { 404 } else {
404 handler->HandleTimeout(); 405 handler->HandleTimeout();
405 } else {
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 | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698