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

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: 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 BUFFER_SIZE = 8 * kInterruptMessageSize;
183 intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]); 183 char buffer[BUFFER_SIZE];
184 for (int i = 0; 184 ssize_t bytes = TEMP_FAILURE_RETRY(read(interrupt_fds_[0],
185 i + kInterruptMessageSize <= available; 185 buffer,
186 i += kInterruptMessageSize) { 186 BUFFER_SIZE));
187 VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0], 187 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) {
Søren Gjesse 2013/11/22 12:40:23 How about InterruptMessage msg[8]; read( ... msg
Anders Johnsen 2013/11/22 12:50:22 Done.
188 reinterpret_cast<char*>(&msg), 188 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(
189 kInterruptMessageSize)); 189 buffer + i * kInterruptMessageSize);
190 if (msg.id == kTimerId) { 190 if (msg->id == kTimerId) {
191 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); 191 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data);
192 } else if (msg.id == kShutdownId) { 192 } else if (msg->id == kShutdownId) {
193 shutdown_ = true; 193 shutdown_ = true;
194 } else { 194 } else {
195 SocketData* sd = GetSocketData(msg.id); 195 SocketData* sd = GetSocketData(msg->id);
196 if ((msg.data & (1 << kShutdownReadCommand)) != 0) { 196 if ((msg->data & (1 << kShutdownReadCommand)) != 0) {
197 ASSERT(msg.data == (1 << kShutdownReadCommand)); 197 ASSERT(msg->data == (1 << kShutdownReadCommand));
198 // Close the socket for reading. 198 // Close the socket for reading.
199 sd->ShutdownRead(); 199 sd->ShutdownRead();
200 UpdateEpollInstance(epoll_fd_, sd); 200 UpdateEpollInstance(epoll_fd_, sd);
201 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { 201 } else if ((msg->data & (1 << kShutdownWriteCommand)) != 0) {
202 ASSERT(msg.data == (1 << kShutdownWriteCommand)); 202 ASSERT(msg->data == (1 << kShutdownWriteCommand));
203 // Close the socket for writing. 203 // Close the socket for writing.
204 sd->ShutdownWrite(); 204 sd->ShutdownWrite();
205 UpdateEpollInstance(epoll_fd_, sd); 205 UpdateEpollInstance(epoll_fd_, sd);
206 } else if ((msg.data & (1 << kCloseCommand)) != 0) { 206 } else if ((msg->data & (1 << kCloseCommand)) != 0) {
207 ASSERT(msg.data == (1 << kCloseCommand)); 207 ASSERT(msg->data == (1 << kCloseCommand));
208 // Close the socket and free system resources and move on to 208 // Close the socket and free system resources and move on to
209 // next message. 209 // next message.
210 RemoveFromEpollInstance(epoll_fd_, sd); 210 RemoveFromEpollInstance(epoll_fd_, sd);
211 intptr_t fd = sd->fd(); 211 intptr_t fd = sd->fd();
212 if (fd == STDOUT_FILENO) { 212 if (fd == STDOUT_FILENO) {
213 // If stdout, redirect fd to /dev/null. 213 // If stdout, redirect fd to /dev/null.
214 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 214 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
215 ASSERT(null_fd >= 0); 215 ASSERT(null_fd >= 0);
216 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); 216 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO));
217 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 217 VOID_TEMP_FAILURE_RETRY(close(null_fd));
218 } else { 218 } else {
219 sd->Close(); 219 sd->Close();
220 } 220 }
221 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 221 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
222 delete sd; 222 delete sd;
223 DartUtils::PostInt32(msg.dart_port, 1 << kDestroyedEvent); 223 DartUtils::PostInt32(msg->dart_port, 1 << kDestroyedEvent);
224 } else { 224 } else {
225 // Setup events to wait for. 225 // Setup events to wait for.
226 sd->SetPortAndMask(msg.dart_port, msg.data); 226 sd->SetPortAndMask(msg->dart_port, msg->data);
227 UpdateEpollInstance(epoll_fd_, sd); 227 UpdateEpollInstance(epoll_fd_, sd);
228 } 228 }
229 } 229 }
230 } 230 }
231 } 231 }
232 232
233 #ifdef DEBUG_POLL 233 #ifdef DEBUG_POLL
234 static void PrintEventMask(intptr_t fd, intptr_t events) { 234 static void PrintEventMask(intptr_t fd, intptr_t events) {
235 Log::Print("%d ", fd); 235 Log::Print("%d ", fd);
236 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); 236 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
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