| 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 "bin/eventhandler.h" | 5 #include "bin/eventhandler.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/epoll.h> | 11 #include <sys/epoll.h> |
| 12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 13 #include <sys/time.h> | |
| 14 #include <unistd.h> | 13 #include <unistd.h> |
| 15 | 14 |
| 16 #include "bin/dartutils.h" | 15 #include "bin/dartutils.h" |
| 17 #include "bin/fdutils.h" | 16 #include "bin/fdutils.h" |
| 18 #include "bin/log.h" | 17 #include "bin/log.h" |
| 18 #include "bin/utils.h" |
| 19 #include "platform/hashmap.h" | 19 #include "platform/hashmap.h" |
| 20 #include "platform/thread.h" | 20 #include "platform/thread.h" |
| 21 #include "platform/utils.h" | 21 #include "platform/utils.h" |
| 22 | 22 |
| 23 | 23 |
| 24 int64_t GetCurrentTimeMilliseconds() { | |
| 25 struct timeval tv; | |
| 26 if (gettimeofday(&tv, NULL) < 0) { | |
| 27 UNREACHABLE(); | |
| 28 return 0; | |
| 29 } | |
| 30 return ((static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec) / 1000; | |
| 31 } | |
| 32 | |
| 33 | |
| 34 static const int kInterruptMessageSize = sizeof(InterruptMessage); | 24 static const int kInterruptMessageSize = sizeof(InterruptMessage); |
| 35 static const int kInfinityTimeout = -1; | 25 static const int kInfinityTimeout = -1; |
| 36 static const int kTimerId = -1; | 26 static const int kTimerId = -1; |
| 37 static const int kShutdownId = -2; | 27 static const int kShutdownId = -2; |
| 38 | 28 |
| 39 | 29 |
| 40 intptr_t SocketData::GetPollEvents() { | 30 intptr_t SocketData::GetPollEvents() { |
| 41 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are | 31 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are |
| 42 // triggered anyway. | 32 // triggered anyway. |
| 43 intptr_t events = 0; | 33 intptr_t events = 0; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } | 341 } |
| 352 } | 342 } |
| 353 HandleInterruptFd(); | 343 HandleInterruptFd(); |
| 354 } | 344 } |
| 355 | 345 |
| 356 | 346 |
| 357 intptr_t EventHandlerImplementation::GetTimeout() { | 347 intptr_t EventHandlerImplementation::GetTimeout() { |
| 358 if (timeout_ == kInfinityTimeout) { | 348 if (timeout_ == kInfinityTimeout) { |
| 359 return kInfinityTimeout; | 349 return kInfinityTimeout; |
| 360 } | 350 } |
| 361 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 351 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 362 return (millis < 0) ? 0 : millis; | 352 return (millis < 0) ? 0 : millis; |
| 363 } | 353 } |
| 364 | 354 |
| 365 | 355 |
| 366 void EventHandlerImplementation::HandleTimeout() { | 356 void EventHandlerImplementation::HandleTimeout() { |
| 367 if (timeout_ != kInfinityTimeout) { | 357 if (timeout_ != kInfinityTimeout) { |
| 368 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 358 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 369 if (millis <= 0) { | 359 if (millis <= 0) { |
| 370 DartUtils::PostNull(timeout_port_); | 360 DartUtils::PostNull(timeout_port_); |
| 371 timeout_ = kInfinityTimeout; | 361 timeout_ = kInfinityTimeout; |
| 372 timeout_port_ = 0; | 362 timeout_port_ = 0; |
| 373 } | 363 } |
| 374 } | 364 } |
| 375 } | 365 } |
| 376 | 366 |
| 377 | 367 |
| 378 void EventHandlerImplementation::Poll(uword args) { | 368 void EventHandlerImplementation::Poll(uword args) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 414 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
| 425 // The hashmap does not support keys with value 0. | 415 // The hashmap does not support keys with value 0. |
| 426 return reinterpret_cast<void*>(fd + 1); | 416 return reinterpret_cast<void*>(fd + 1); |
| 427 } | 417 } |
| 428 | 418 |
| 429 | 419 |
| 430 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 420 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 431 // The hashmap does not support keys with value 0. | 421 // The hashmap does not support keys with value 0. |
| 432 return dart::Utils::WordHash(fd + 1); | 422 return dart::Utils::WordHash(fd + 1); |
| 433 } | 423 } |
| OLD | NEW |