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

Side by Side Diff: runtime/bin/eventhandler_linux.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, 1 month 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 | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.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_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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (result != kInterruptMessageSize) { 177 if (result != kInterruptMessageSize) {
178 if (result == -1) { 178 if (result == -1) {
179 perror("Interrupt message failure:"); 179 perror("Interrupt message failure:");
180 } 180 }
181 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); 181 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result);
182 } 182 }
183 } 183 }
184 184
185 185
186 void EventHandlerImplementation::HandleInterruptFd() { 186 void EventHandlerImplementation::HandleInterruptFd() {
187 InterruptMessage msg; 187 const intptr_t MAX_MESSAGES = kInterruptMessageSize;
188 intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]); 188 InterruptMessage msg[MAX_MESSAGES];
189 for (int i = 0; 189 ssize_t bytes = TEMP_FAILURE_RETRY(
190 i + kInterruptMessageSize <= available; 190 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize));
191 i += kInterruptMessageSize) { 191 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) {
192 VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0], 192 if (msg[i].id == kTimerId) {
193 reinterpret_cast<char*>(&msg), 193 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data);
194 kInterruptMessageSize)); 194 } else if (msg[i].id == kShutdownId) {
195 if (msg.id == kTimerId) {
196 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data);
197 } else if (msg.id == kShutdownId) {
198 shutdown_ = true; 195 shutdown_ = true;
199 } else { 196 } else {
200 SocketData* sd = GetSocketData(msg.id); 197 SocketData* sd = GetSocketData(msg[i].id);
201 if ((msg.data & (1 << kShutdownReadCommand)) != 0) { 198 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) {
202 ASSERT(msg.data == (1 << kShutdownReadCommand)); 199 ASSERT(msg[i].data == (1 << kShutdownReadCommand));
203 // Close the socket for reading. 200 // Close the socket for reading.
204 sd->ShutdownRead(); 201 sd->ShutdownRead();
205 UpdateEpollInstance(epoll_fd_, sd); 202 UpdateEpollInstance(epoll_fd_, sd);
206 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { 203 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) {
207 ASSERT(msg.data == (1 << kShutdownWriteCommand)); 204 ASSERT(msg[i].data == (1 << kShutdownWriteCommand));
208 // Close the socket for writing. 205 // Close the socket for writing.
209 sd->ShutdownWrite(); 206 sd->ShutdownWrite();
210 UpdateEpollInstance(epoll_fd_, sd); 207 UpdateEpollInstance(epoll_fd_, sd);
211 } else if ((msg.data & (1 << kCloseCommand)) != 0) { 208 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) {
212 ASSERT(msg.data == (1 << kCloseCommand)); 209 ASSERT(msg[i].data == (1 << kCloseCommand));
213 // Close the socket and free system resources and move on to 210 // Close the socket and free system resources and move on to
214 // next message. 211 // next message.
215 RemoveFromEpollInstance(epoll_fd_, sd); 212 RemoveFromEpollInstance(epoll_fd_, sd);
216 intptr_t fd = sd->fd(); 213 intptr_t fd = sd->fd();
217 if (fd == STDOUT_FILENO) { 214 if (fd == STDOUT_FILENO) {
218 // If stdout, redirect fd to /dev/null. 215 // If stdout, redirect fd to /dev/null.
219 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 216 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
220 ASSERT(null_fd >= 0); 217 ASSERT(null_fd >= 0);
221 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); 218 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO));
222 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 219 VOID_TEMP_FAILURE_RETRY(close(null_fd));
223 } else { 220 } else {
224 sd->Close(); 221 sd->Close();
225 } 222 }
226 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 223 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
227 delete sd; 224 delete sd;
228 DartUtils::PostInt32(msg.dart_port, 1 << kDestroyedEvent); 225 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent);
229 } else { 226 } else {
230 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { 227 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) {
231 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); 228 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent);
232 } else { 229 } else {
233 // Setup events to wait for. 230 // Setup events to wait for.
234 sd->SetPortAndMask(msg.dart_port, msg.data); 231 sd->SetPortAndMask(msg[i].dart_port, msg[i].data);
235 UpdateEpollInstance(epoll_fd_, sd); 232 UpdateEpollInstance(epoll_fd_, sd);
236 } 233 }
237 } 234 }
238 } 235 }
239 } 236 }
240 } 237 }
241 238
242 #ifdef DEBUG_POLL 239 #ifdef DEBUG_POLL
243 static void PrintEventMask(intptr_t fd, intptr_t events) { 240 static void PrintEventMask(intptr_t fd, intptr_t events) {
244 Log::Print("%d ", fd); 241 Log::Print("%d ", fd);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 437
441 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 438 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
442 // The hashmap does not support keys with value 0. 439 // The hashmap does not support keys with value 0.
443 return dart::Utils::WordHash(fd + 1); 440 return dart::Utils::WordHash(fd + 1);
444 } 441 }
445 442
446 } // namespace bin 443 } // namespace bin
447 } // namespace dart 444 } // namespace dart
448 445
449 #endif // defined(TARGET_OS_LINUX) 446 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698