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

Side by Side Diff: runtime/bin/eventhandler_macos.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 | « runtime/bin/eventhandler_linux.cc ('k') | 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_MACOS) 6 #if defined(TARGET_OS_MACOS)
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (result != kInterruptMessageSize) { 192 if (result != kInterruptMessageSize) {
193 if (result == -1) { 193 if (result == -1) {
194 perror("Interrupt message failure:"); 194 perror("Interrupt message failure:");
195 } 195 }
196 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); 196 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result);
197 } 197 }
198 } 198 }
199 199
200 200
201 void EventHandlerImplementation::HandleInterruptFd() { 201 void EventHandlerImplementation::HandleInterruptFd() {
202 InterruptMessage msg; 202 const intptr_t MAX_MESSAGES = kInterruptMessageSize;
203 intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]); 203 InterruptMessage msg[MAX_MESSAGES];
204 for (int i = 0; 204 ssize_t bytes = TEMP_FAILURE_RETRY(
205 i + kInterruptMessageSize <= available; 205 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize));
206 i += kInterruptMessageSize) { 206 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) {
207 VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0], 207 if (msg[i].id == kTimerId) {
208 reinterpret_cast<char*>(&msg), 208 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data);
209 kInterruptMessageSize)); 209 } else if (msg[i].id == kShutdownId) {
210 if (msg.id == kTimerId) {
211 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data);
212 } else if (msg.id == kShutdownId) {
213 shutdown_ = true; 210 shutdown_ = true;
214 } else { 211 } else {
215 SocketData* sd = GetSocketData(msg.id); 212 SocketData* sd = GetSocketData(msg[i].id);
216 if ((msg.data & (1 << kShutdownReadCommand)) != 0) { 213 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) {
217 ASSERT(msg.data == (1 << kShutdownReadCommand)); 214 ASSERT(msg[i].data == (1 << kShutdownReadCommand));
218 // Close the socket for reading. 215 // Close the socket for reading.
219 sd->ShutdownRead(); 216 sd->ShutdownRead();
220 UpdateKqueue(kqueue_fd_, sd); 217 UpdateKqueue(kqueue_fd_, sd);
221 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { 218 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) {
222 ASSERT(msg.data == (1 << kShutdownWriteCommand)); 219 ASSERT(msg[i].data == (1 << kShutdownWriteCommand));
223 // Close the socket for writing. 220 // Close the socket for writing.
224 sd->ShutdownWrite(); 221 sd->ShutdownWrite();
225 UpdateKqueue(kqueue_fd_, sd); 222 UpdateKqueue(kqueue_fd_, sd);
226 } else if ((msg.data & (1 << kCloseCommand)) != 0) { 223 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) {
227 ASSERT(msg.data == (1 << kCloseCommand)); 224 ASSERT(msg[i].data == (1 << kCloseCommand));
228 // Close the socket and free system resources. 225 // Close the socket and free system resources.
229 RemoveFromKqueue(kqueue_fd_, sd); 226 RemoveFromKqueue(kqueue_fd_, sd);
230 intptr_t fd = sd->fd(); 227 intptr_t fd = sd->fd();
231 if (fd == STDOUT_FILENO) { 228 if (fd == STDOUT_FILENO) {
232 // If stdout, redirect fd to /dev/null. 229 // If stdout, redirect fd to /dev/null.
233 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 230 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
234 ASSERT(null_fd >= 0); 231 ASSERT(null_fd >= 0);
235 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); 232 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO));
236 VOID_TEMP_FAILURE_RETRY(close(null_fd)); 233 VOID_TEMP_FAILURE_RETRY(close(null_fd));
237 } else { 234 } else {
238 sd->Close(); 235 sd->Close();
239 } 236 }
240 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 237 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
241 delete sd; 238 delete sd;
242 DartUtils::PostInt32(msg.dart_port, 1 << kDestroyedEvent); 239 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent);
243 } else { 240 } else {
244 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { 241 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) {
245 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); 242 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent);
246 } else { 243 } else {
247 // Setup events to wait for. 244 // Setup events to wait for.
248 sd->SetPortAndMask(msg.dart_port, msg.data); 245 sd->SetPortAndMask(msg[i].dart_port, msg[i].data);
249 UpdateKqueue(kqueue_fd_, sd); 246 UpdateKqueue(kqueue_fd_, sd);
250 } 247 }
251 } 248 }
252 } 249 }
253 } 250 }
254 } 251 }
255 252
256 #ifdef DEBUG_KQUEUE 253 #ifdef DEBUG_KQUEUE
257 static void PrintEventMask(intptr_t fd, struct kevent* event) { 254 static void PrintEventMask(intptr_t fd, struct kevent* event) {
258 Log::Print("%d ", static_cast<int>(fd)); 255 Log::Print("%d ", static_cast<int>(fd));
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 447
451 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 448 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
452 // The hashmap does not support keys with value 0. 449 // The hashmap does not support keys with value 0.
453 return dart::Utils::WordHash(fd + 1); 450 return dart::Utils::WordHash(fd + 1);
454 } 451 }
455 452
456 } // namespace bin 453 } // namespace bin
457 } // namespace dart 454 } // namespace dart
458 455
459 #endif // defined(TARGET_OS_MACOS) 456 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698