| OLD | NEW |
| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 | 353 |
| 354 | 354 |
| 355 void EventHandlerImplementation::EventHandlerEntry(uword args) { | 355 void EventHandlerImplementation::EventHandlerEntry(uword args) { |
| 356 static const intptr_t kMaxEvents = 16; | 356 static const intptr_t kMaxEvents = 16; |
| 357 struct kevent events[kMaxEvents]; | 357 struct kevent events[kMaxEvents]; |
| 358 EventHandler* handler = reinterpret_cast<EventHandler*>(args); | 358 EventHandler* handler = reinterpret_cast<EventHandler*>(args); |
| 359 EventHandlerImplementation* handler_impl = &handler->delegate_; | 359 EventHandlerImplementation* handler_impl = &handler->delegate_; |
| 360 ASSERT(handler_impl != NULL); | 360 ASSERT(handler_impl != NULL); |
| 361 |
| 361 while (!handler_impl->shutdown_) { | 362 while (!handler_impl->shutdown_) { |
| 362 int64_t millis = handler_impl->GetTimeout(); | 363 int64_t millis = handler_impl->GetTimeout(); |
| 363 ASSERT(millis == kInfinityTimeout || millis >= 0); | 364 ASSERT(millis == kInfinityTimeout || millis >= 0); |
| 364 if (millis > kMaxInt32) millis = kMaxInt32; | 365 if (millis > kMaxInt32) millis = kMaxInt32; |
| 365 // NULL pointer timespec for infinite timeout. | 366 // NULL pointer timespec for infinite timeout. |
| 366 ASSERT(kInfinityTimeout < 0); | 367 ASSERT(kInfinityTimeout < 0); |
| 367 struct timespec* timeout = NULL; | 368 struct timespec* timeout = NULL; |
| 368 struct timespec ts; | 369 struct timespec ts; |
| 369 if (millis >= 0) { | 370 if (millis >= 0) { |
| 370 int32_t millis32 = static_cast<int32_t>(millis); | 371 int32_t millis32 = static_cast<int32_t>(millis); |
| 371 int32_t secs = millis32 / 1000; | 372 int32_t secs = millis32 / 1000; |
| 372 ts.tv_sec = secs; | 373 ts.tv_sec = secs; |
| 373 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000; | 374 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000; |
| 374 timeout = &ts; | 375 timeout = &ts; |
| 375 } | 376 } |
| 376 // We have to use TEMP_FAILURE_RETRY for mac, as kevent can modify the | 377 // We have to use TEMP_FAILURE_RETRY for mac, as kevent can modify the |
| 377 // current sigmask. | 378 // current sigmask. |
| 378 intptr_t result = TEMP_FAILURE_RETRY( | 379 intptr_t result = TEMP_FAILURE_RETRY( |
| 379 kevent(handler_impl->kqueue_fd_, NULL, 0, events, kMaxEvents, timeout)); | 380 kevent(handler_impl->kqueue_fd_, NULL, 0, events, kMaxEvents, timeout)); |
| 380 if (result == -1) { | 381 if (result == -1) { |
| 381 const int kBufferSize = 1024; | 382 const int kBufferSize = 1024; |
| 382 char error_message[kBufferSize]; | 383 char error_message[kBufferSize]; |
| 383 strerror_r(errno, error_message, kBufferSize); | 384 strerror_r(errno, error_message, kBufferSize); |
| 384 FATAL1("kevent failed %s\n", error_message); | 385 FATAL1("kevent failed %s\n", error_message); |
| 385 } else { | 386 } else { |
| 386 handler_impl->HandleTimeout(); | 387 handler_impl->HandleTimeout(); |
| 387 handler_impl->HandleEvents(events, result); | 388 handler_impl->HandleEvents(events, result); |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 delete handler; | 391 handler->NotifyShutdownDone(); |
| 391 } | 392 } |
| 392 | 393 |
| 393 | 394 |
| 394 void EventHandlerImplementation::Start(EventHandler* handler) { | 395 void EventHandlerImplementation::Start(EventHandler* handler) { |
| 395 int result = | 396 int result = |
| 396 Thread::Start(&EventHandlerImplementation::EventHandlerEntry, | 397 Thread::Start(&EventHandlerImplementation::EventHandlerEntry, |
| 397 reinterpret_cast<uword>(handler)); | 398 reinterpret_cast<uword>(handler)); |
| 398 if (result != 0) { | 399 if (result != 0) { |
| 399 FATAL1("Failed to start event handler thread %d", result); | 400 FATAL1("Failed to start event handler thread %d", result); |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 | 403 |
| 403 | 404 |
| 404 void EventHandlerImplementation::Shutdown() { | 405 void EventHandlerImplementation::Shutdown() { |
| 405 SendData(kShutdownId, 0, 0); | 406 SendData(kShutdownId, 0, 0); |
| 406 } | 407 } |
| 407 | 408 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 421 | 422 |
| 422 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 423 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 423 // The hashmap does not support keys with value 0. | 424 // The hashmap does not support keys with value 0. |
| 424 return dart::Utils::WordHash(fd + 1); | 425 return dart::Utils::WordHash(fd + 1); |
| 425 } | 426 } |
| 426 | 427 |
| 427 } // namespace bin | 428 } // namespace bin |
| 428 } // namespace dart | 429 } // namespace dart |
| 429 | 430 |
| 430 #endif // defined(TARGET_OS_MACOS) | 431 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |