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_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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 Dart_Port port = sd->port(); | 343 Dart_Port port = sd->port(); |
344 ASSERT(port != 0); | 344 ASSERT(port != 0); |
345 DartUtils::PostInt32(port, event_mask); | 345 DartUtils::PostInt32(port, event_mask); |
346 } | 346 } |
347 } | 347 } |
348 } | 348 } |
349 HandleInterruptFd(); | 349 HandleInterruptFd(); |
350 } | 350 } |
351 | 351 |
352 | 352 |
353 intptr_t EventHandlerImplementation::GetTimeout() { | 353 int64_t EventHandlerImplementation::GetTimeout() { |
354 if (timeout_ == kInfinityTimeout) { | 354 if (timeout_ == kInfinityTimeout) { |
355 return kInfinityTimeout; | 355 return kInfinityTimeout; |
356 } | 356 } |
357 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); | 357 int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
358 return (millis < 0) ? 0 : millis; | 358 return (millis < 0) ? 0 : millis; |
359 } | 359 } |
360 | 360 |
361 | 361 |
362 void EventHandlerImplementation::HandleTimeout() { | 362 void EventHandlerImplementation::HandleTimeout() { |
363 if (timeout_ != kInfinityTimeout) { | 363 if (timeout_ != kInfinityTimeout) { |
364 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); | 364 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
365 if (millis <= 0) { | 365 if (millis <= 0) { |
366 DartUtils::PostNull(timeout_port_); | 366 DartUtils::PostNull(timeout_port_); |
367 timeout_ = kInfinityTimeout; | 367 timeout_ = kInfinityTimeout; |
368 timeout_port_ = 0; | 368 timeout_port_ = 0; |
369 } | 369 } |
370 } | 370 } |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 void EventHandlerImplementation::Poll(uword args) { | 374 void EventHandlerImplementation::Poll(uword args) { |
375 static const intptr_t kMaxEvents = 16; | 375 static const intptr_t kMaxEvents = 16; |
376 struct epoll_event events[kMaxEvents]; | 376 struct epoll_event events[kMaxEvents]; |
377 EventHandlerImplementation* handler = | 377 EventHandlerImplementation* handler = |
378 reinterpret_cast<EventHandlerImplementation*>(args); | 378 reinterpret_cast<EventHandlerImplementation*>(args); |
379 ASSERT(handler != NULL); | 379 ASSERT(handler != NULL); |
380 while (!handler->shutdown_) { | 380 while (!handler->shutdown_) { |
381 intptr_t millis = handler->GetTimeout(); | 381 int64_t millis = handler->GetTimeout(); |
| 382 ASSERT(millis == kInfinityTimeout || millis >= 0); |
| 383 if (millis > kMaxInt32) millis = kMaxInt32; |
382 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_, | 384 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler->epoll_fd_, |
383 events, | 385 events, |
384 kMaxEvents, | 386 kMaxEvents, |
385 millis)); | 387 millis)); |
386 ASSERT(EAGAIN == EWOULDBLOCK); | 388 ASSERT(EAGAIN == EWOULDBLOCK); |
387 if (result == -1) { | 389 if (result == -1) { |
388 if (errno != EWOULDBLOCK) { | 390 if (errno != EWOULDBLOCK) { |
389 perror("Poll failed"); | 391 perror("Poll failed"); |
390 } | 392 } |
391 } else { | 393 } else { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 427 |
426 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 428 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
427 // The hashmap does not support keys with value 0. | 429 // The hashmap does not support keys with value 0. |
428 return dart::Utils::WordHash(fd + 1); | 430 return dart::Utils::WordHash(fd + 1); |
429 } | 431 } |
430 | 432 |
431 } // namespace bin | 433 } // namespace bin |
432 } // namespace dart | 434 } // namespace dart |
433 | 435 |
434 #endif // defined(TARGET_OS_ANDROID) | 436 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |