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

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

Issue 83173003: Read up to 8 InterruptMessages at a time, in unix eventhandlers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup. 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (result != kInterruptMessageSize) { 172 if (result != kInterruptMessageSize) {
173 if (result == -1) { 173 if (result == -1) {
174 perror("Interrupt message failure:"); 174 perror("Interrupt message failure:");
175 } 175 }
176 FATAL1("Interrupt message failure. Wrote %d bytes.", result); 176 FATAL1("Interrupt message failure. Wrote %d bytes.", result);
177 } 177 }
178 } 178 }
179 179
180 180
181 void EventHandlerImplementation::HandleInterruptFd() { 181 void EventHandlerImplementation::HandleInterruptFd() {
182 InterruptMessage msg; 182 const intptr_t MAX_MESSAGES = kInterruptMessageSize;
183 intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]); 183 InterruptMessage msg[MAX_MESSAGES];
184 for (int i = 0; 184 ssize_t bytes = TEMP_FAILURE_RETRY(
185 i + kInterruptMessageSize <= available; 185 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize));
186 i += kInterruptMessageSize) { 186 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) {
187 VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0], 187 if (msg[i].id == kTimerId) {
188 reinterpret_cast<char*>(&msg), 188 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data);
189 kInterruptMessageSize)); 189 } else if (msg[i].id == kShutdownId) {
190 if (msg.id == kTimerId) {
191 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data);
192 } else if (msg.id == kShutdownId) {
193 shutdown_ = true; 190 shutdown_ = true;
194 } else { 191 } else {
195 SocketData* sd = GetSocketData(msg.id); 192 SocketData* sd = GetSocketData(msg[i].id);
196 if ((msg.data & (1 << kShutdownReadCommand)) != 0) { 193 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) {
197 ASSERT(msg.data == (1 << kShutdownReadCommand)); 194 ASSERT(msg[i].data == (1 << kShutdownReadCommand));
198 // Close the socket for reading. 195 // Close the socket for reading.
199 sd->ShutdownRead(); 196 sd->ShutdownRead();
200 UpdateEpollInstance(epoll_fd_, sd); 197 UpdateEpollInstance(epoll_fd_, sd);
201 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { 198 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) {
202 ASSERT(msg.data == (1 << kShutdownWriteCommand)); 199 ASSERT(msg[i].data == (1 << kShutdownWriteCommand));
203 // Close the socket for writing. 200 // Close the socket for writing.
204 sd->ShutdownWrite(); 201 sd->ShutdownWrite();
205 UpdateEpollInstance(epoll_fd_, sd); 202 UpdateEpollInstance(epoll_fd_, sd);
206 } else if ((msg.data & (1 << kCloseCommand)) != 0) { 203 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) {
207 ASSERT(msg.data == (1 << kCloseCommand)); 204 ASSERT(msg[i].data == (1 << kCloseCommand));
208 // Close the socket and free system resources and move on to 205 // Close the socket and free system resources and move on to
209 // next message. 206 // next message.
210 RemoveFromEpollInstance(epoll_fd_, sd); 207 RemoveFromEpollInstance(epoll_fd_, sd);
211 intptr_t fd = sd->fd(); 208 intptr_t fd = sd->fd();
212 if (fd == STDOUT_FILENO) { 209 if (fd == STDOUT_FILENO) {
213 // If stdout, redirect fd to /dev/null. 210 // If stdout, redirect fd to /dev/null.
214 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 211 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
215 ASSERT(null_fd >= 0); 212 ASSERT(null_fd >= 0);
216 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); 213 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO));
217 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 214 VOID_TEMP_FAILURE_RETRY(close(null_fd));
218 } else { 215 } else {
219 sd->Close(); 216 sd->Close();
220 } 217 }
221 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 218 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
222 delete sd; 219 delete sd;
223 DartUtils::PostInt32(msg.dart_port, 1 << kDestroyedEvent); 220 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent);
224 } else { 221 } else {
225 // Setup events to wait for. 222 // Setup events to wait for.
226 sd->SetPortAndMask(msg.dart_port, msg.data); 223 sd->SetPortAndMask(msg[i].dart_port, msg[i].data);
227 UpdateEpollInstance(epoll_fd_, sd); 224 UpdateEpollInstance(epoll_fd_, sd);
228 } 225 }
229 } 226 }
230 } 227 }
231 } 228 }
232 229
233 #ifdef DEBUG_POLL 230 #ifdef DEBUG_POLL
234 static void PrintEventMask(intptr_t fd, intptr_t events) { 231 static void PrintEventMask(intptr_t fd, intptr_t events) {
235 Log::Print("%d ", fd); 232 Log::Print("%d ", fd);
236 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); 233 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 435
439 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 436 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
440 // The hashmap does not support keys with value 0. 437 // The hashmap does not support keys with value 0.
441 return dart::Utils::WordHash(fd + 1); 438 return dart::Utils::WordHash(fd + 1);
442 } 439 }
443 440
444 } // namespace bin 441 } // namespace bin
445 } // namespace dart 442 } // namespace dart
446 443
447 #endif // defined(TARGET_OS_ANDROID) 444 #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