| 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/event.h> | 11 #include <sys/event.h> |
| 12 #include <sys/time.h> | |
| 13 #include <unistd.h> | 12 #include <unistd.h> |
| 14 | 13 |
| 15 #include "bin/dartutils.h" | 14 #include "bin/dartutils.h" |
| 16 #include "bin/fdutils.h" | 15 #include "bin/fdutils.h" |
| 17 #include "bin/log.h" | 16 #include "bin/log.h" |
| 17 #include "bin/utils.h" |
| 18 #include "platform/hashmap.h" | 18 #include "platform/hashmap.h" |
| 19 #include "platform/thread.h" | 19 #include "platform/thread.h" |
| 20 #include "platform/utils.h" | 20 #include "platform/utils.h" |
| 21 | 21 |
| 22 | 22 |
| 23 int64_t GetCurrentTimeMilliseconds() { | |
| 24 struct timeval tv; | |
| 25 if (gettimeofday(&tv, NULL) < 0) { | |
| 26 UNREACHABLE(); | |
| 27 return 0; | |
| 28 } | |
| 29 return ((static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec) / 1000; | |
| 30 } | |
| 31 | |
| 32 | |
| 33 static const int kInterruptMessageSize = sizeof(InterruptMessage); | 23 static const int kInterruptMessageSize = sizeof(InterruptMessage); |
| 34 static const int kInfinityTimeout = -1; | 24 static const int kInfinityTimeout = -1; |
| 35 static const int kTimerId = -1; | 25 static const int kTimerId = -1; |
| 36 static const int kShutdownId = -2; | 26 static const int kShutdownId = -2; |
| 37 | 27 |
| 38 | 28 |
| 39 bool SocketData::HasReadEvent() { | 29 bool SocketData::HasReadEvent() { |
| 40 return !IsClosedRead() && ((mask_ & (1 << kInEvent)) != 0); | 30 return !IsClosedRead() && ((mask_ & (1 << kInEvent)) != 0); |
| 41 } | 31 } |
| 42 | 32 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 326 } |
| 337 } | 327 } |
| 338 HandleInterruptFd(); | 328 HandleInterruptFd(); |
| 339 } | 329 } |
| 340 | 330 |
| 341 | 331 |
| 342 intptr_t EventHandlerImplementation::GetTimeout() { | 332 intptr_t EventHandlerImplementation::GetTimeout() { |
| 343 if (timeout_ == kInfinityTimeout) { | 333 if (timeout_ == kInfinityTimeout) { |
| 344 return kInfinityTimeout; | 334 return kInfinityTimeout; |
| 345 } | 335 } |
| 346 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 336 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 347 return (millis < 0) ? 0 : millis; | 337 return (millis < 0) ? 0 : millis; |
| 348 } | 338 } |
| 349 | 339 |
| 350 | 340 |
| 351 void EventHandlerImplementation::HandleTimeout() { | 341 void EventHandlerImplementation::HandleTimeout() { |
| 352 if (timeout_ != kInfinityTimeout) { | 342 if (timeout_ != kInfinityTimeout) { |
| 353 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 343 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 354 if (millis <= 0) { | 344 if (millis <= 0) { |
| 355 DartUtils::PostNull(timeout_port_); | 345 DartUtils::PostNull(timeout_port_); |
| 356 timeout_ = kInfinityTimeout; | 346 timeout_ = kInfinityTimeout; |
| 357 timeout_port_ = 0; | 347 timeout_port_ = 0; |
| 358 } | 348 } |
| 359 } | 349 } |
| 360 } | 350 } |
| 361 | 351 |
| 362 | 352 |
| 363 void EventHandlerImplementation::EventHandlerEntry(uword args) { | 353 void EventHandlerImplementation::EventHandlerEntry(uword args) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 408 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
| 419 // The hashmap does not support keys with value 0. | 409 // The hashmap does not support keys with value 0. |
| 420 return reinterpret_cast<void*>(fd + 1); | 410 return reinterpret_cast<void*>(fd + 1); |
| 421 } | 411 } |
| 422 | 412 |
| 423 | 413 |
| 424 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 414 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(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 dart::Utils::WordHash(fd + 1); | 416 return dart::Utils::WordHash(fd + 1); |
| 427 } | 417 } |
| OLD | NEW |