| 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_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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 308 } |
| 309 | 309 |
| 310 | 310 |
| 311 void EventHandlerImplementation::Poll(uword args) { | 311 void EventHandlerImplementation::Poll(uword args) { |
| 312 ThreadSignalBlocker signal_blocker(SIGPROF); | 312 ThreadSignalBlocker signal_blocker(SIGPROF); |
| 313 static const intptr_t kMaxEvents = 16; | 313 static const intptr_t kMaxEvents = 16; |
| 314 struct epoll_event events[kMaxEvents]; | 314 struct epoll_event events[kMaxEvents]; |
| 315 EventHandler* handler = reinterpret_cast<EventHandler*>(args); | 315 EventHandler* handler = reinterpret_cast<EventHandler*>(args); |
| 316 EventHandlerImplementation* handler_impl = &handler->delegate_; | 316 EventHandlerImplementation* handler_impl = &handler->delegate_; |
| 317 ASSERT(handler_impl != NULL); | 317 ASSERT(handler_impl != NULL); |
| 318 |
| 318 while (!handler_impl->shutdown_) { | 319 while (!handler_impl->shutdown_) { |
| 319 intptr_t result = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER( | 320 intptr_t result = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER( |
| 320 epoll_wait(handler_impl->epoll_fd_, events, kMaxEvents, -1)); | 321 epoll_wait(handler_impl->epoll_fd_, events, kMaxEvents, -1)); |
| 321 ASSERT(EAGAIN == EWOULDBLOCK); | 322 ASSERT(EAGAIN == EWOULDBLOCK); |
| 322 if (result <= 0) { | 323 if (result <= 0) { |
| 323 if (errno != EWOULDBLOCK) { | 324 if (errno != EWOULDBLOCK) { |
| 324 perror("Poll failed"); | 325 perror("Poll failed"); |
| 325 } | 326 } |
| 326 } else { | 327 } else { |
| 327 handler_impl->HandleEvents(events, result); | 328 handler_impl->HandleEvents(events, result); |
| 328 } | 329 } |
| 329 } | 330 } |
| 330 delete handler; | 331 handler->NotifyShutdownDone(); |
| 331 } | 332 } |
| 332 | 333 |
| 333 | 334 |
| 334 void EventHandlerImplementation::Start(EventHandler* handler) { | 335 void EventHandlerImplementation::Start(EventHandler* handler) { |
| 335 int result = Thread::Start(&EventHandlerImplementation::Poll, | 336 int result = Thread::Start(&EventHandlerImplementation::Poll, |
| 336 reinterpret_cast<uword>(handler)); | 337 reinterpret_cast<uword>(handler)); |
| 337 if (result != 0) { | 338 if (result != 0) { |
| 338 FATAL1("Failed to start event handler thread %d", result); | 339 FATAL1("Failed to start event handler thread %d", result); |
| 339 } | 340 } |
| 340 } | 341 } |
| 341 | 342 |
| 342 | 343 |
| 343 void EventHandlerImplementation::Shutdown() { | 344 void EventHandlerImplementation::Shutdown() { |
| 344 SendData(kShutdownId, 0, 0); | 345 SendData(kShutdownId, 0, 0); |
| 345 } | 346 } |
| 346 | 347 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 360 | 361 |
| 361 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 362 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 362 // The hashmap does not support keys with value 0. | 363 // The hashmap does not support keys with value 0. |
| 363 return dart::Utils::WordHash(fd + 1); | 364 return dart::Utils::WordHash(fd + 1); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace bin | 367 } // namespace bin |
| 367 } // namespace dart | 368 } // namespace dart |
| 368 | 369 |
| 369 #endif // defined(TARGET_OS_LINUX) | 370 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |