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

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

Powered by Google App Engine
This is Rietveld 408576698