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

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

Issue 209333014: Speed up GetRandomBytes by only entering signal-blocking scope once. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add validation and apply in other scenario. Created 6 years, 8 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.cc ('k') | runtime/bin/eventhandler_macos.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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 perror("Interrupt message failure:"); 165 perror("Interrupt message failure:");
166 } 166 }
167 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); 167 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result);
168 } 168 }
169 } 169 }
170 170
171 171
172 void EventHandlerImplementation::HandleInterruptFd() { 172 void EventHandlerImplementation::HandleInterruptFd() {
173 const intptr_t MAX_MESSAGES = kInterruptMessageSize; 173 const intptr_t MAX_MESSAGES = kInterruptMessageSize;
174 InterruptMessage msg[MAX_MESSAGES]; 174 InterruptMessage msg[MAX_MESSAGES];
175 ssize_t bytes = TEMP_FAILURE_RETRY( 175 ssize_t bytes = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
176 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); 176 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize));
177 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { 177 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) {
178 if (msg[i].id == kTimerId) { 178 if (msg[i].id == kTimerId) {
179 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); 179 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data);
180 struct itimerspec it; 180 struct itimerspec it;
181 memset(&it, 0, sizeof(it)); 181 memset(&it, 0, sizeof(it));
182 if (timeout_queue_.HasTimeout()) { 182 if (timeout_queue_.HasTimeout()) {
183 int64_t millis = timeout_queue_.CurrentTimeout(); 183 int64_t millis = timeout_queue_.CurrentTimeout();
184 it.it_value.tv_sec = millis / 1000; 184 it.it_value.tv_sec = millis / 1000;
185 it.it_value.tv_nsec = (millis % 1000) * 1000000; 185 it.it_value.tv_nsec = (millis % 1000) * 1000000;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 260
261 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 261 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
262 int size) { 262 int size) {
263 bool interrupt_seen = false; 263 bool interrupt_seen = false;
264 for (int i = 0; i < size; i++) { 264 for (int i = 0; i < size; i++) {
265 if (events[i].data.ptr == NULL) { 265 if (events[i].data.ptr == NULL) {
266 interrupt_seen = true; 266 interrupt_seen = true;
267 } else if (events[i].data.fd == timer_fd_) { 267 } else if (events[i].data.fd == timer_fd_) {
268 int64_t val; 268 int64_t val;
269 VOID_TEMP_FAILURE_RETRY(read(timer_fd_, &val, sizeof(val))); 269 VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
270 read(timer_fd_, &val, sizeof(val)));
270 if (timeout_queue_.HasTimeout()) { 271 if (timeout_queue_.HasTimeout()) {
271 DartUtils::PostNull(timeout_queue_.CurrentPort()); 272 DartUtils::PostNull(timeout_queue_.CurrentPort());
272 timeout_queue_.RemoveCurrent(); 273 timeout_queue_.RemoveCurrent();
273 } 274 }
274 } else { 275 } else {
275 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); 276 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
276 intptr_t event_mask = GetPollEvents(events[i].events, sd); 277 intptr_t event_mask = GetPollEvents(events[i].events, sd);
277 if (event_mask != 0) { 278 if (event_mask != 0) {
278 if (sd->TakeToken()) { 279 if (sd->TakeToken()) {
279 // Took last token, remove from epoll. 280 // Took last token, remove from epoll.
280 RemoveFromEpollInstance(epoll_fd_, sd); 281 RemoveFromEpollInstance(epoll_fd_, sd);
281 } 282 }
282 Dart_Port port = sd->port(); 283 Dart_Port port = sd->port();
283 ASSERT(port != 0); 284 ASSERT(port != 0);
284 DartUtils::PostInt32(port, event_mask); 285 DartUtils::PostInt32(port, event_mask);
285 } 286 }
286 } 287 }
287 } 288 }
288 if (interrupt_seen) { 289 if (interrupt_seen) {
289 // Handle after socket events, so we avoid closing a socket before we handle 290 // Handle after socket events, so we avoid closing a socket before we handle
290 // the current events. 291 // the current events.
291 HandleInterruptFd(); 292 HandleInterruptFd();
292 } 293 }
293 } 294 }
294 295
295 296
296 void EventHandlerImplementation::Poll(uword args) { 297 void EventHandlerImplementation::Poll(uword args) {
298 ThreadSignalBlocker signal_blocker(SIGPROF);
297 static const intptr_t kMaxEvents = 16; 299 static const intptr_t kMaxEvents = 16;
298 struct epoll_event events[kMaxEvents]; 300 struct epoll_event events[kMaxEvents];
299 EventHandler* handler = reinterpret_cast<EventHandler*>(args); 301 EventHandler* handler = reinterpret_cast<EventHandler*>(args);
300 EventHandlerImplementation* handler_impl = &handler->delegate_; 302 EventHandlerImplementation* handler_impl = &handler->delegate_;
301 ASSERT(handler_impl != NULL); 303 ASSERT(handler_impl != NULL);
302 while (!handler_impl->shutdown_) { 304 while (!handler_impl->shutdown_) {
303 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_, 305 intptr_t result = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
304 events, 306 epoll_wait(handler_impl->epoll_fd_, events, kMaxEvents, -1));
305 kMaxEvents,
306 -1));
307 ASSERT(EAGAIN == EWOULDBLOCK); 307 ASSERT(EAGAIN == EWOULDBLOCK);
308 if (result <= 0) { 308 if (result <= 0) {
309 if (errno != EWOULDBLOCK) { 309 if (errno != EWOULDBLOCK) {
310 perror("Poll failed"); 310 perror("Poll failed");
311 } 311 }
312 } else { 312 } else {
313 handler_impl->HandleEvents(events, result); 313 handler_impl->HandleEvents(events, result);
314 } 314 }
315 } 315 }
316 delete handler; 316 delete handler;
(...skipping 29 matching lines...) Expand all
346 346
347 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 347 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
348 // The hashmap does not support keys with value 0. 348 // The hashmap does not support keys with value 0.
349 return dart::Utils::WordHash(fd + 1); 349 return dart::Utils::WordHash(fd + 1);
350 } 350 }
351 351
352 } // namespace bin 352 } // namespace bin
353 } // namespace dart 353 } // namespace dart
354 354
355 #endif // defined(TARGET_OS_LINUX) 355 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698