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

Side by Side Diff: runtime/bin/eventhandler_android.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_android.h ('k') | runtime/bin/eventhandler_linux.h » ('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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 if ((mask_ & (1 << kOutEvent)) != 0) { 50 if ((mask_ & (1 << kOutEvent)) != 0) {
51 events |= EPOLLOUT; 51 events |= EPOLLOUT;
52 } 52 }
53 return events; 53 return events;
54 } 54 }
55 55
56 56
57 // Unregister the file descriptor for a SocketData structure with epoll. 57 // Unregister the file descriptor for a SocketData structure with epoll.
58 static void RemoveFromEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 58 static void RemoveFromEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
59 VOID_TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 59 VOID_NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
60 EPOLL_CTL_DEL, 60 EPOLL_CTL_DEL,
61 sd->fd(), 61 sd->fd(),
62 NULL)); 62 NULL));
63 } 63 }
64 64
65 65
66 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 66 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
67 struct epoll_event event; 67 struct epoll_event event;
68 event.events = sd->GetPollEvents(); 68 event.events = sd->GetPollEvents();
69 event.data.ptr = sd; 69 event.data.ptr = sd;
70 int status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 70 int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
71 EPOLL_CTL_ADD, 71 EPOLL_CTL_ADD,
72 sd->fd(), 72 sd->fd(),
73 &event)); 73 &event));
74 if (status == -1) { 74 if (status == -1) {
75 // Epoll does not accept the file descriptor. It could be due to 75 // Epoll does not accept the file descriptor. It could be due to
76 // already closed file descriptor, or unuspported devices, such 76 // already closed file descriptor, or unuspported devices, such
77 // as /dev/null. In such case, mark the file descriptor as closed, 77 // as /dev/null. In such case, mark the file descriptor as closed,
78 // so dart will handle it accordingly. 78 // so dart will handle it accordingly.
79 DartUtils::PostInt32(sd->port(), 1 << kCloseEvent); 79 DartUtils::PostInt32(sd->port(), 1 << kCloseEvent);
80 } 80 }
81 } 81 }
82 82
83 83
84 EventHandlerImplementation::EventHandlerImplementation() 84 EventHandlerImplementation::EventHandlerImplementation()
85 : socket_map_(&HashMap::SamePointerValue, 16) { 85 : socket_map_(&HashMap::SamePointerValue, 16) {
86 intptr_t result; 86 intptr_t result;
87 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); 87 result = NO_RETRY_EXPECTED(pipe(interrupt_fds_));
88 if (result != 0) { 88 if (result != 0) {
89 FATAL("Pipe creation failed"); 89 FATAL("Pipe creation failed");
90 } 90 }
91 FDUtils::SetNonBlocking(interrupt_fds_[0]); 91 FDUtils::SetNonBlocking(interrupt_fds_[0]);
92 FDUtils::SetCloseOnExec(interrupt_fds_[0]); 92 FDUtils::SetCloseOnExec(interrupt_fds_[0]);
93 FDUtils::SetCloseOnExec(interrupt_fds_[1]); 93 FDUtils::SetCloseOnExec(interrupt_fds_[1]);
94 shutdown_ = false; 94 shutdown_ = false;
95 // The initial size passed to epoll_create is ignore on newer (>= 95 // The initial size passed to epoll_create is ignore on newer (>=
96 // 2.6.8) Linux versions 96 // 2.6.8) Linux versions
97 static const int kEpollInitialSize = 64; 97 static const int kEpollInitialSize = 64;
98 epoll_fd_ = TEMP_FAILURE_RETRY(epoll_create(kEpollInitialSize)); 98 epoll_fd_ = NO_RETRY_EXPECTED(epoll_create(kEpollInitialSize));
99 if (epoll_fd_ == -1) { 99 if (epoll_fd_ == -1) {
100 FATAL("Failed creating epoll file descriptor"); 100 FATAL("Failed creating epoll file descriptor");
101 } 101 }
102 FDUtils::SetCloseOnExec(epoll_fd_); 102 FDUtils::SetCloseOnExec(epoll_fd_);
103 // Register the interrupt_fd with the epoll instance. 103 // Register the interrupt_fd with the epoll instance.
104 struct epoll_event event; 104 struct epoll_event event;
105 event.events = EPOLLIN; 105 event.events = EPOLLIN;
106 event.data.ptr = NULL; 106 event.data.ptr = NULL;
107 int status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 107 int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
108 EPOLL_CTL_ADD, 108 EPOLL_CTL_ADD,
109 interrupt_fds_[0], 109 interrupt_fds_[0],
110 &event)); 110 &event));
111 if (status == -1) { 111 if (status == -1) {
112 FATAL("Failed adding interrupt fd to epoll instance"); 112 FATAL("Failed adding interrupt fd to epoll instance");
113 } 113 }
114 } 114 }
115 115
116 116
117 EventHandlerImplementation::~EventHandlerImplementation() { 117 EventHandlerImplementation::~EventHandlerImplementation() {
118 TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); 118 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0]));
119 TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); 119 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1]));
120 } 120 }
121 121
122 122
123 SocketData* EventHandlerImplementation::GetSocketData(intptr_t fd) { 123 SocketData* EventHandlerImplementation::GetSocketData(intptr_t fd) {
124 ASSERT(fd >= 0); 124 ASSERT(fd >= 0);
125 HashMap::Entry* entry = socket_map_.Lookup( 125 HashMap::Entry* entry = socket_map_.Lookup(
126 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true); 126 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true);
127 ASSERT(entry != NULL); 127 ASSERT(entry != NULL);
128 SocketData* sd = reinterpret_cast<SocketData*>(entry->value); 128 SocketData* sd = reinterpret_cast<SocketData*>(entry->value);
129 if (sd == NULL) { 129 if (sd == NULL) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 346 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
347 // The hashmap does not support keys with value 0. 347 // The hashmap does not support keys with value 0.
348 return dart::Utils::WordHash(fd + 1); 348 return dart::Utils::WordHash(fd + 1);
349 } 349 }
350 350
351 } // namespace bin 351 } // namespace bin
352 } // namespace dart 352 } // namespace dart
353 353
354 #endif // defined(TARGET_OS_ANDROID) 354 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_android.h ('k') | runtime/bin/eventhandler_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698