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

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

Issue 1466523002: Landing patch set 7 from https://codereview.chromium.org/1450113003/ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « runtime/bin/dbg_connection_macos.cc ('k') | runtime/bin/file_android.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_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 #include "bin/eventhandler_macos.h" 9 #include "bin/eventhandler_macos.h"
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 FATAL("Failed creating kqueue"); 125 FATAL("Failed creating kqueue");
126 } 126 }
127 FDUtils::SetCloseOnExec(kqueue_fd_); 127 FDUtils::SetCloseOnExec(kqueue_fd_);
128 // Register the interrupt_fd with the kqueue. 128 // Register the interrupt_fd with the kqueue.
129 struct kevent event; 129 struct kevent event;
130 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL); 130 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL);
131 int status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); 131 int status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL));
132 if (status == -1) { 132 if (status == -1) {
133 const int kBufferSize = 1024; 133 const int kBufferSize = 1024;
134 char error_message[kBufferSize]; 134 char error_message[kBufferSize];
135 strerror_r(errno, error_message, kBufferSize); 135 Utils::StrError(errno, error_message, kBufferSize);
136 FATAL1("Failed adding interrupt fd to kqueue: %s\n", error_message); 136 FATAL1("Failed adding interrupt fd to kqueue: %s\n", error_message);
137 } 137 }
138 } 138 }
139 139
140 140
141 EventHandlerImplementation::~EventHandlerImplementation() { 141 EventHandlerImplementation::~EventHandlerImplementation() {
142 VOID_TEMP_FAILURE_RETRY(close(kqueue_fd_)); 142 VOID_TEMP_FAILURE_RETRY(close(kqueue_fd_));
143 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); 143 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0]));
144 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); 144 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1]));
145 } 145 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 352
353 void EventHandlerImplementation::HandleEvents(struct kevent* events, 353 void EventHandlerImplementation::HandleEvents(struct kevent* events,
354 int size) { 354 int size) {
355 bool interrupt_seen = false; 355 bool interrupt_seen = false;
356 for (int i = 0; i < size; i++) { 356 for (int i = 0; i < size; i++) {
357 // If flag EV_ERROR is set it indicates an error in kevent processing. 357 // If flag EV_ERROR is set it indicates an error in kevent processing.
358 if ((events[i].flags & EV_ERROR) != 0) { 358 if ((events[i].flags & EV_ERROR) != 0) {
359 const int kBufferSize = 1024; 359 const int kBufferSize = 1024;
360 char error_message[kBufferSize]; 360 char error_message[kBufferSize];
361 strerror_r(events[i].data, error_message, kBufferSize); 361 Utils::StrError(events[i].data, error_message, kBufferSize);
362 FATAL1("kevent failed %s\n", error_message); 362 FATAL1("kevent failed %s\n", error_message);
363 } 363 }
364 if (events[i].udata == NULL) { 364 if (events[i].udata == NULL) {
365 interrupt_seen = true; 365 interrupt_seen = true;
366 } else { 366 } else {
367 DescriptorInfo* di = 367 DescriptorInfo* di =
368 reinterpret_cast<DescriptorInfo*>(events[i].udata); 368 reinterpret_cast<DescriptorInfo*>(events[i].udata);
369 intptr_t event_mask = GetEvents(events + i, di); 369 intptr_t event_mask = GetEvents(events + i, di);
370 if ((event_mask & (1 << kErrorEvent)) != 0) { 370 if ((event_mask & (1 << kErrorEvent)) != 0) {
371 di->NotifyAllDartPorts(event_mask); 371 di->NotifyAllDartPorts(event_mask);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000; 433 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000;
434 timeout = &ts; 434 timeout = &ts;
435 } 435 }
436 // We have to use TEMP_FAILURE_RETRY for mac, as kevent can modify the 436 // We have to use TEMP_FAILURE_RETRY for mac, as kevent can modify the
437 // current sigmask. 437 // current sigmask.
438 intptr_t result = TEMP_FAILURE_RETRY( 438 intptr_t result = TEMP_FAILURE_RETRY(
439 kevent(handler_impl->kqueue_fd_, NULL, 0, events, kMaxEvents, timeout)); 439 kevent(handler_impl->kqueue_fd_, NULL, 0, events, kMaxEvents, timeout));
440 if (result == -1) { 440 if (result == -1) {
441 const int kBufferSize = 1024; 441 const int kBufferSize = 1024;
442 char error_message[kBufferSize]; 442 char error_message[kBufferSize];
443 strerror_r(errno, error_message, kBufferSize); 443 Utils::StrError(errno, error_message, kBufferSize);
444 FATAL1("kevent failed %s\n", error_message); 444 FATAL1("kevent failed %s\n", error_message);
445 } else { 445 } else {
446 handler_impl->HandleTimeout(); 446 handler_impl->HandleTimeout();
447 handler_impl->HandleEvents(events, result); 447 handler_impl->HandleEvents(events, result);
448 } 448 }
449 } 449 }
450 handler->NotifyShutdownDone(); 450 handler->NotifyShutdownDone();
451 } 451 }
452 452
453 453
(...skipping 27 matching lines...) Expand all
481 481
482 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 482 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
483 // The hashmap does not support keys with value 0. 483 // The hashmap does not support keys with value 0.
484 return dart::Utils::WordHash(fd + 1); 484 return dart::Utils::WordHash(fd + 1);
485 } 485 }
486 486
487 } // namespace bin 487 } // namespace bin
488 } // namespace dart 488 } // namespace dart
489 489
490 #endif // defined(TARGET_OS_MACOS) 490 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/dbg_connection_macos.cc ('k') | runtime/bin/file_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698