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

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

Issue 165723007: Move signal_blocker to platform and use it by default in TEMP_FAILURE_RETRY. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tiny fix. Created 6 years, 9 months 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_macos.h ('k') | runtime/bin/fdutils_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 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return (mask_ & (1 << kOutEvent)) != 0; 42 return (mask_ & (1 << kOutEvent)) != 0;
43 } 43 }
44 44
45 45
46 // Unregister the file descriptor for a SocketData structure with kqueue. 46 // Unregister the file descriptor for a SocketData structure with kqueue.
47 static void RemoveFromKqueue(intptr_t kqueue_fd_, SocketData* sd) { 47 static void RemoveFromKqueue(intptr_t kqueue_fd_, SocketData* sd) {
48 if (!sd->tracked_by_kqueue()) return; 48 if (!sd->tracked_by_kqueue()) return;
49 static const intptr_t kMaxChanges = 2; 49 static const intptr_t kMaxChanges = 2;
50 struct kevent events[kMaxChanges]; 50 struct kevent events[kMaxChanges];
51 EV_SET(events, sd->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL); 51 EV_SET(events, sd->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
52 VOID_TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, 1, NULL, 0, NULL)); 52 VOID_NO_RETRY_EXPECTED(kevent(kqueue_fd_, events, 1, NULL, 0, NULL));
53 EV_SET(events, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); 53 EV_SET(events, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
54 VOID_TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, 1, NULL, 0, NULL)); 54 VOID_NO_RETRY_EXPECTED(kevent(kqueue_fd_, events, 1, NULL, 0, NULL));
55 sd->set_tracked_by_kqueue(false); 55 sd->set_tracked_by_kqueue(false);
56 } 56 }
57 57
58 58
59 // Update the kqueue registration for SocketData structure to reflect 59 // Update the kqueue registration for SocketData structure to reflect
60 // the events currently of interest. 60 // the events currently of interest.
61 static void AddToKqueue(intptr_t kqueue_fd_, SocketData* sd) { 61 static void AddToKqueue(intptr_t kqueue_fd_, SocketData* sd) {
62 ASSERT(!sd->tracked_by_kqueue()); 62 ASSERT(!sd->tracked_by_kqueue());
63 static const intptr_t kMaxChanges = 2; 63 static const intptr_t kMaxChanges = 2;
64 intptr_t changes = 0; 64 intptr_t changes = 0;
(...skipping 16 matching lines...) Expand all
81 EVFILT_WRITE, 81 EVFILT_WRITE,
82 EV_ADD | EV_CLEAR, 82 EV_ADD | EV_CLEAR,
83 0, 83 0,
84 0, 84 0,
85 sd); 85 sd);
86 ++changes; 86 ++changes;
87 } 87 }
88 ASSERT(changes > 0); 88 ASSERT(changes > 0);
89 ASSERT(changes <= kMaxChanges); 89 ASSERT(changes <= kMaxChanges);
90 int status = 90 int status =
91 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); 91 NO_RETRY_EXPECTED(kevent(kqueue_fd_, events, changes, NULL, 0, NULL));
92 if (status == -1) { 92 if (status == -1) {
93 // kQueue does not accept the file descriptor. It could be due to 93 // kQueue does not accept the file descriptor. It could be due to
94 // already closed file descriptor, or unuspported devices, such 94 // already closed file descriptor, or unuspported devices, such
95 // as /dev/null. In such case, mark the file descriptor as closed, 95 // as /dev/null. In such case, mark the file descriptor as closed,
96 // so dart will handle it accordingly. 96 // so dart will handle it accordingly.
97 DartUtils::PostInt32(sd->port(), 1 << kCloseEvent); 97 DartUtils::PostInt32(sd->port(), 1 << kCloseEvent);
98 } else { 98 } else {
99 sd->set_tracked_by_kqueue(true); 99 sd->set_tracked_by_kqueue(true);
100 } 100 }
101 } 101 }
102 102
103 103
104 EventHandlerImplementation::EventHandlerImplementation() 104 EventHandlerImplementation::EventHandlerImplementation()
105 : socket_map_(&HashMap::SamePointerValue, 16) { 105 : socket_map_(&HashMap::SamePointerValue, 16) {
106 intptr_t result; 106 intptr_t result;
107 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); 107 result = NO_RETRY_EXPECTED(pipe(interrupt_fds_));
108 if (result != 0) { 108 if (result != 0) {
109 FATAL("Pipe creation failed"); 109 FATAL("Pipe creation failed");
110 } 110 }
111 FDUtils::SetNonBlocking(interrupt_fds_[0]); 111 FDUtils::SetNonBlocking(interrupt_fds_[0]);
112 FDUtils::SetCloseOnExec(interrupt_fds_[0]); 112 FDUtils::SetCloseOnExec(interrupt_fds_[0]);
113 FDUtils::SetCloseOnExec(interrupt_fds_[1]); 113 FDUtils::SetCloseOnExec(interrupt_fds_[1]);
114 shutdown_ = false; 114 shutdown_ = false;
115 115
116 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); 116 kqueue_fd_ = NO_RETRY_EXPECTED(kqueue());
117 if (kqueue_fd_ == -1) { 117 if (kqueue_fd_ == -1) {
118 FATAL("Failed creating kqueue"); 118 FATAL("Failed creating kqueue");
119 } 119 }
120 FDUtils::SetCloseOnExec(kqueue_fd_); 120 FDUtils::SetCloseOnExec(kqueue_fd_);
121 // Register the interrupt_fd with the kqueue. 121 // Register the interrupt_fd with the kqueue.
122 struct kevent event; 122 struct kevent event;
123 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL); 123 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL);
124 int status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); 124 int status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL));
125 if (status == -1) { 125 if (status == -1) {
126 const int kBufferSize = 1024; 126 const int kBufferSize = 1024;
127 char error_message[kBufferSize]; 127 char error_message[kBufferSize];
128 strerror_r(errno, error_message, kBufferSize); 128 strerror_r(errno, error_message, kBufferSize);
129 FATAL1("Failed adding interrupt fd to kqueue: %s\n", error_message); 129 FATAL1("Failed adding interrupt fd to kqueue: %s\n", error_message);
130 } 130 }
131 } 131 }
132 132
133 133
134 EventHandlerImplementation::~EventHandlerImplementation() { 134 EventHandlerImplementation::~EventHandlerImplementation() {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 419 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
420 // The hashmap does not support keys with value 0. 420 // The hashmap does not support keys with value 0.
421 return dart::Utils::WordHash(fd + 1); 421 return dart::Utils::WordHash(fd + 1);
422 } 422 }
423 423
424 } // namespace bin 424 } // namespace bin
425 } // namespace dart 425 } // namespace dart
426 426
427 #endif // defined(TARGET_OS_MACOS) 427 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_macos.h ('k') | runtime/bin/fdutils_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698