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

Side by Side Diff: runtime/bin/eventhandler_macos.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, 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_linux.cc ('k') | runtime/platform/signal_blocker.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_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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 perror("Interrupt message failure:"); 172 perror("Interrupt message failure:");
173 } 173 }
174 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); 174 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result);
175 } 175 }
176 } 176 }
177 177
178 178
179 void EventHandlerImplementation::HandleInterruptFd() { 179 void EventHandlerImplementation::HandleInterruptFd() {
180 const intptr_t MAX_MESSAGES = kInterruptMessageSize; 180 const intptr_t MAX_MESSAGES = kInterruptMessageSize;
181 InterruptMessage msg[MAX_MESSAGES]; 181 InterruptMessage msg[MAX_MESSAGES];
182 ssize_t bytes = TEMP_FAILURE_RETRY( 182 ssize_t bytes = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
183 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); 183 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize));
184 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { 184 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) {
185 if (msg[i].id == kTimerId) { 185 if (msg[i].id == kTimerId) {
186 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); 186 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data);
187 } else if (msg[i].id == kShutdownId) { 187 } else if (msg[i].id == kShutdownId) {
188 shutdown_ = true; 188 shutdown_ = true;
189 } else { 189 } else {
190 SocketData* sd = GetSocketData(msg[i].id); 190 SocketData* sd = GetSocketData(msg[i].id);
191 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) { 191 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) {
192 ASSERT(msg[i].data == (1 << kShutdownReadCommand)); 192 ASSERT(msg[i].data == (1 << kShutdownReadCommand));
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 TimerUtils::GetCurrentTimeMilliseconds(); 341 TimerUtils::GetCurrentTimeMilliseconds();
342 if (millis <= 0) { 342 if (millis <= 0) {
343 DartUtils::PostNull(timeout_queue_.CurrentPort()); 343 DartUtils::PostNull(timeout_queue_.CurrentPort());
344 timeout_queue_.RemoveCurrent(); 344 timeout_queue_.RemoveCurrent();
345 } 345 }
346 } 346 }
347 } 347 }
348 348
349 349
350 void EventHandlerImplementation::EventHandlerEntry(uword args) { 350 void EventHandlerImplementation::EventHandlerEntry(uword args) {
351 ThreadSignalBlocker signal_blocker(SIGPROF);
351 static const intptr_t kMaxEvents = 16; 352 static const intptr_t kMaxEvents = 16;
352 struct kevent events[kMaxEvents]; 353 struct kevent events[kMaxEvents];
353 EventHandler* handler = reinterpret_cast<EventHandler*>(args); 354 EventHandler* handler = reinterpret_cast<EventHandler*>(args);
354 EventHandlerImplementation* handler_impl = &handler->delegate_; 355 EventHandlerImplementation* handler_impl = &handler->delegate_;
355 ASSERT(handler_impl != NULL); 356 ASSERT(handler_impl != NULL);
356 while (!handler_impl->shutdown_) { 357 while (!handler_impl->shutdown_) {
357 int64_t millis = handler_impl->GetTimeout(); 358 int64_t millis = handler_impl->GetTimeout();
358 ASSERT(millis == kInfinityTimeout || millis >= 0); 359 ASSERT(millis == kInfinityTimeout || millis >= 0);
359 if (millis > kMaxInt32) millis = kMaxInt32; 360 if (millis > kMaxInt32) millis = kMaxInt32;
360 // NULL pointer timespec for infinite timeout. 361 // NULL pointer timespec for infinite timeout.
361 ASSERT(kInfinityTimeout < 0); 362 ASSERT(kInfinityTimeout < 0);
362 struct timespec* timeout = NULL; 363 struct timespec* timeout = NULL;
363 struct timespec ts; 364 struct timespec ts;
364 if (millis >= 0) { 365 if (millis >= 0) {
365 int32_t millis32 = static_cast<int32_t>(millis); 366 int32_t millis32 = static_cast<int32_t>(millis);
366 int32_t secs = millis32 / 1000; 367 int32_t secs = millis32 / 1000;
367 ts.tv_sec = secs; 368 ts.tv_sec = secs;
368 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000; 369 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000;
369 timeout = &ts; 370 timeout = &ts;
370 } 371 }
371 intptr_t result = TEMP_FAILURE_RETRY(kevent(handler_impl->kqueue_fd_, 372 intptr_t result = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
372 NULL, 373 kevent(handler_impl->kqueue_fd_, NULL, 0, events, kMaxEvents, timeout));
373 0,
374 events,
375 kMaxEvents,
376 timeout));
377 if (result == -1) { 374 if (result == -1) {
378 const int kBufferSize = 1024; 375 const int kBufferSize = 1024;
379 char error_message[kBufferSize]; 376 char error_message[kBufferSize];
380 strerror_r(errno, error_message, kBufferSize); 377 strerror_r(errno, error_message, kBufferSize);
381 FATAL1("kevent failed %s\n", error_message); 378 FATAL1("kevent failed %s\n", error_message);
382 } else { 379 } else {
383 handler_impl->HandleTimeout(); 380 handler_impl->HandleTimeout();
384 handler_impl->HandleEvents(events, result); 381 handler_impl->HandleEvents(events, result);
385 } 382 }
386 } 383 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 415
419 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 416 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
420 // The hashmap does not support keys with value 0. 417 // The hashmap does not support keys with value 0.
421 return dart::Utils::WordHash(fd + 1); 418 return dart::Utils::WordHash(fd + 1);
422 } 419 }
423 420
424 } // namespace bin 421 } // namespace bin
425 } // namespace dart 422 } // namespace dart
426 423
427 #endif // defined(TARGET_OS_MACOS) 424 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_linux.cc ('k') | runtime/platform/signal_blocker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698