| Index: src/platform/default-platform-time.cc
|
| diff --git a/src/platform/time.cc b/src/platform/default-platform-time.cc
|
| similarity index 59%
|
| copy from src/platform/time.cc
|
| copy to src/platform/default-platform-time.cc
|
| index de0ca16473f6b5106485508653cfe797f6632c37..5273b45ab6267e461f8fbe800438dfb7b62959ce 100644
|
| --- a/src/platform/time.cc
|
| +++ b/src/platform/default-platform-time.cc
|
| @@ -25,7 +25,7 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -#include "platform/time.h"
|
| +#include "default-platform.h"
|
|
|
| #if V8_OS_POSIX
|
| #include <sys/time.h>
|
| @@ -34,11 +34,10 @@
|
| #include <mach/mach_time.h>
|
| #endif
|
|
|
| -#include <cstring>
|
| -
|
| #include "checks.h"
|
| #include "cpu.h"
|
| -#include "platform.h"
|
| +#include "platform/time.h"
|
| +#include "v8.h"
|
| #if V8_OS_WIN
|
| #include "win32-headers.h"
|
| #endif
|
| @@ -46,121 +45,6 @@
|
| namespace v8 {
|
| namespace internal {
|
|
|
| -TimeDelta TimeDelta::FromDays(int days) {
|
| - return TimeDelta(days * Time::kMicrosecondsPerDay);
|
| -}
|
| -
|
| -
|
| -TimeDelta TimeDelta::FromHours(int hours) {
|
| - return TimeDelta(hours * Time::kMicrosecondsPerHour);
|
| -}
|
| -
|
| -
|
| -TimeDelta TimeDelta::FromMinutes(int minutes) {
|
| - return TimeDelta(minutes * Time::kMicrosecondsPerMinute);
|
| -}
|
| -
|
| -
|
| -TimeDelta TimeDelta::FromSeconds(int64_t seconds) {
|
| - return TimeDelta(seconds * Time::kMicrosecondsPerSecond);
|
| -}
|
| -
|
| -
|
| -TimeDelta TimeDelta::FromMilliseconds(int64_t milliseconds) {
|
| - return TimeDelta(milliseconds * Time::kMicrosecondsPerMillisecond);
|
| -}
|
| -
|
| -
|
| -TimeDelta TimeDelta::FromNanoseconds(int64_t nanoseconds) {
|
| - return TimeDelta(nanoseconds / Time::kNanosecondsPerMicrosecond);
|
| -}
|
| -
|
| -
|
| -int TimeDelta::InDays() const {
|
| - return static_cast<int>(delta_ / Time::kMicrosecondsPerDay);
|
| -}
|
| -
|
| -
|
| -int TimeDelta::InHours() const {
|
| - return static_cast<int>(delta_ / Time::kMicrosecondsPerHour);
|
| -}
|
| -
|
| -
|
| -int TimeDelta::InMinutes() const {
|
| - return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute);
|
| -}
|
| -
|
| -
|
| -double TimeDelta::InSecondsF() const {
|
| - return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond;
|
| -}
|
| -
|
| -
|
| -int64_t TimeDelta::InSeconds() const {
|
| - return delta_ / Time::kMicrosecondsPerSecond;
|
| -}
|
| -
|
| -
|
| -double TimeDelta::InMillisecondsF() const {
|
| - return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
|
| -}
|
| -
|
| -
|
| -int64_t TimeDelta::InMilliseconds() const {
|
| - return delta_ / Time::kMicrosecondsPerMillisecond;
|
| -}
|
| -
|
| -
|
| -int64_t TimeDelta::InNanoseconds() const {
|
| - return delta_ * Time::kNanosecondsPerMicrosecond;
|
| -}
|
| -
|
| -
|
| -#if V8_OS_MACOSX
|
| -
|
| -TimeDelta TimeDelta::FromMachTimespec(struct mach_timespec ts) {
|
| - ASSERT_GE(ts.tv_nsec, 0);
|
| - ASSERT_LT(ts.tv_nsec,
|
| - static_cast<long>(Time::kNanosecondsPerSecond)); // NOLINT
|
| - return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond +
|
| - ts.tv_nsec / Time::kNanosecondsPerMicrosecond);
|
| -}
|
| -
|
| -
|
| -struct mach_timespec TimeDelta::ToMachTimespec() const {
|
| - struct mach_timespec ts;
|
| - ASSERT(delta_ >= 0);
|
| - ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond;
|
| - ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) *
|
| - Time::kNanosecondsPerMicrosecond;
|
| - return ts;
|
| -}
|
| -
|
| -#endif // V8_OS_MACOSX
|
| -
|
| -
|
| -#if V8_OS_POSIX
|
| -
|
| -TimeDelta TimeDelta::FromTimespec(struct timespec ts) {
|
| - ASSERT_GE(ts.tv_nsec, 0);
|
| - ASSERT_LT(ts.tv_nsec,
|
| - static_cast<long>(Time::kNanosecondsPerSecond)); // NOLINT
|
| - return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond +
|
| - ts.tv_nsec / Time::kNanosecondsPerMicrosecond);
|
| -}
|
| -
|
| -
|
| -struct timespec TimeDelta::ToTimespec() const {
|
| - struct timespec ts;
|
| - ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond;
|
| - ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) *
|
| - Time::kNanosecondsPerMicrosecond;
|
| - return ts;
|
| -}
|
| -
|
| -#endif // V8_OS_POSIX
|
| -
|
| -
|
| #if V8_OS_WIN
|
|
|
| // We implement time using the high-resolution timers so that we can get
|
| @@ -221,160 +105,33 @@ static LazyStaticInstance<Clock,
|
| ThreadSafeInitOnceTrait>::type clock = LAZY_STATIC_INSTANCE_INITIALIZER;
|
|
|
|
|
| -Time Time::Now() {
|
| - return clock.Pointer()->Now();
|
| +double DefaultPlatform::CurrentTime() {
|
| + return clock.Pointer()->Now().ToInternalValue();
|
| }
|
|
|
|
|
| -Time Time::NowFromSystemTime() {
|
| - return clock.Pointer()->NowFromSystemTime();
|
| -}
|
| -
|
| -
|
| -// Time between windows epoch and standard epoch.
|
| -static const int64_t kTimeToEpochInMicroseconds = V8_INT64_C(11644473600000000);
|
| -
|
| -
|
| -Time Time::FromFiletime(FILETIME ft) {
|
| - if (ft.dwLowDateTime == 0 && ft.dwHighDateTime == 0) {
|
| - return Time();
|
| - }
|
| - if (ft.dwLowDateTime == std::numeric_limits<DWORD>::max() &&
|
| - ft.dwHighDateTime == std::numeric_limits<DWORD>::max()) {
|
| - return Max();
|
| - }
|
| - int64_t us = (static_cast<uint64_t>(ft.dwLowDateTime) +
|
| - (static_cast<uint64_t>(ft.dwHighDateTime) << 32)) / 10;
|
| - return Time(us - kTimeToEpochInMicroseconds);
|
| -}
|
| -
|
| -
|
| -FILETIME Time::ToFiletime() const {
|
| - ASSERT(us_ >= 0);
|
| - FILETIME ft;
|
| - if (IsNull()) {
|
| - ft.dwLowDateTime = 0;
|
| - ft.dwHighDateTime = 0;
|
| - return ft;
|
| - }
|
| - if (IsMax()) {
|
| - ft.dwLowDateTime = std::numeric_limits<DWORD>::max();
|
| - ft.dwHighDateTime = std::numeric_limits<DWORD>::max();
|
| - return ft;
|
| - }
|
| - uint64_t us = static_cast<uint64_t>(us_ + kTimeToEpochInMicroseconds) * 10;
|
| - ft.dwLowDateTime = static_cast<DWORD>(us);
|
| - ft.dwHighDateTime = static_cast<DWORD>(us >> 32);
|
| - return ft;
|
| +double DefaultPlatform::CurrentTimeFromSystemTime() {
|
| + return clock.Pointer()->NowFromSystemTime().ToInternalValue();
|
| }
|
|
|
| #elif V8_OS_POSIX
|
|
|
| -Time Time::Now() {
|
| +int64_t DefaultPlatform::CurrentTime() {
|
| struct timeval tv;
|
| int result = gettimeofday(&tv, NULL);
|
| ASSERT_EQ(0, result);
|
| USE(result);
|
| - return FromTimeval(tv);
|
| -}
|
| -
|
| -
|
| -Time Time::NowFromSystemTime() {
|
| - return Now();
|
| -}
|
| -
|
| -
|
| -Time Time::FromTimespec(struct timespec ts) {
|
| - ASSERT(ts.tv_nsec >= 0);
|
| - ASSERT(ts.tv_nsec < static_cast<long>(kNanosecondsPerSecond)); // NOLINT
|
| - if (ts.tv_nsec == 0 && ts.tv_sec == 0) {
|
| - return Time();
|
| - }
|
| - if (ts.tv_nsec == static_cast<long>(kNanosecondsPerSecond - 1) && // NOLINT
|
| - ts.tv_sec == std::numeric_limits<time_t>::max()) {
|
| - return Max();
|
| - }
|
| - return Time(ts.tv_sec * kMicrosecondsPerSecond +
|
| - ts.tv_nsec / kNanosecondsPerMicrosecond);
|
| -}
|
| -
|
| -
|
| -struct timespec Time::ToTimespec() const {
|
| - struct timespec ts;
|
| - if (IsNull()) {
|
| - ts.tv_sec = 0;
|
| - ts.tv_nsec = 0;
|
| - return ts;
|
| - }
|
| - if (IsMax()) {
|
| - ts.tv_sec = std::numeric_limits<time_t>::max();
|
| - ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT
|
| - return ts;
|
| - }
|
| - ts.tv_sec = us_ / kMicrosecondsPerSecond;
|
| - ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond;
|
| - return ts;
|
| + return Time::FromTimeval(tv).ToInternalValue();
|
| }
|
|
|
|
|
| -Time Time::FromTimeval(struct timeval tv) {
|
| - ASSERT(tv.tv_usec >= 0);
|
| - ASSERT(tv.tv_usec < static_cast<suseconds_t>(kMicrosecondsPerSecond));
|
| - if (tv.tv_usec == 0 && tv.tv_sec == 0) {
|
| - return Time();
|
| - }
|
| - if (tv.tv_usec == static_cast<suseconds_t>(kMicrosecondsPerSecond - 1) &&
|
| - tv.tv_sec == std::numeric_limits<time_t>::max()) {
|
| - return Max();
|
| - }
|
| - return Time(tv.tv_sec * kMicrosecondsPerSecond + tv.tv_usec);
|
| -}
|
| -
|
| -
|
| -struct timeval Time::ToTimeval() const {
|
| - struct timeval tv;
|
| - if (IsNull()) {
|
| - tv.tv_sec = 0;
|
| - tv.tv_usec = 0;
|
| - return tv;
|
| - }
|
| - if (IsMax()) {
|
| - tv.tv_sec = std::numeric_limits<time_t>::max();
|
| - tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1);
|
| - return tv;
|
| - }
|
| - tv.tv_sec = us_ / kMicrosecondsPerSecond;
|
| - tv.tv_usec = us_ % kMicrosecondsPerSecond;
|
| - return tv;
|
| +int64_t DefaultPlatform::CurrentTimeFromSystemTime() {
|
| + return CurrentTime();
|
| }
|
|
|
| #endif // V8_OS_WIN
|
|
|
|
|
| -Time Time::FromJsTime(double ms_since_epoch) {
|
| - // The epoch is a valid time, so this constructor doesn't interpret
|
| - // 0 as the null time.
|
| - if (ms_since_epoch == std::numeric_limits<double>::max()) {
|
| - return Max();
|
| - }
|
| - return Time(
|
| - static_cast<int64_t>(ms_since_epoch * kMicrosecondsPerMillisecond));
|
| -}
|
| -
|
| -
|
| -double Time::ToJsTime() const {
|
| - if (IsNull()) {
|
| - // Preserve 0 so the invalid result doesn't depend on the platform.
|
| - return 0;
|
| - }
|
| - if (IsMax()) {
|
| - // Preserve max without offset to prevent overflow.
|
| - return std::numeric_limits<double>::max();
|
| - }
|
| - return static_cast<double>(us_) / kMicrosecondsPerMillisecond;
|
| -}
|
| -
|
| -
|
| #if V8_OS_WIN
|
|
|
| class TickClock {
|
| @@ -511,42 +268,29 @@ struct CreateHighResTickClockTrait {
|
| }
|
| };
|
|
|
| -
|
| static LazyDynamicInstance<TickClock,
|
| CreateHighResTickClockTrait,
|
| ThreadSafeInitOnceTrait>::type high_res_tick_clock =
|
| LAZY_DYNAMIC_INSTANCE_INITIALIZER;
|
|
|
|
|
| -TimeTicks TimeTicks::Now() {
|
| - // Make sure we never return 0 here.
|
| - TimeTicks ticks(tick_clock.Pointer()->Now());
|
| - ASSERT(!ticks.IsNull());
|
| - return ticks;
|
| +int64_t DefaultPlatform::TimeTicksNow() {
|
| + return tick_clock.Pointer()->Now();
|
| }
|
|
|
|
|
| -TimeTicks TimeTicks::HighResolutionNow() {
|
| - // Make sure we never return 0 here.
|
| - TimeTicks ticks(high_res_tick_clock.Pointer()->Now());
|
| - ASSERT(!ticks.IsNull());
|
| - return ticks;
|
| +int64_t DefaultPlatform::TimeTicksHighResNow() {
|
| + return high_res_tick_clock.Pointer()->Now();
|
| }
|
|
|
|
|
| -// static
|
| -bool TimeTicks::IsHighResolutionClockWorking() {
|
| +bool DefaultPlatform::TimeTicksHasHighRes() {
|
| return high_res_tick_clock.Pointer()->IsHighResolution();
|
| }
|
|
|
| #else // V8_OS_WIN
|
|
|
| -TimeTicks TimeTicks::Now() {
|
| - return HighResolutionNow();
|
| -}
|
| -
|
| -
|
| -TimeTicks TimeTicks::HighResolutionNow() {
|
| +int64_t DefaultPlatform::TimeTicksHighResNow() {
|
| int64_t ticks;
|
| #if V8_OS_MACOSX
|
| static struct mach_timebase_info info;
|
| @@ -577,12 +321,16 @@ TimeTicks TimeTicks::HighResolutionNow() {
|
| ts.tv_nsec / Time::kNanosecondsPerMicrosecond);
|
| #endif // V8_OS_MACOSX
|
| // Make sure we never return 0 here.
|
| - return TimeTicks(ticks + 1);
|
| + return ticks + 1;
|
| +}
|
| +
|
| +
|
| +int64_t DefaultPlatform::TimeTicksNow() {
|
| + return DefaultPlatform::TimeTicksHighResNow();
|
| }
|
|
|
|
|
| -// static
|
| -bool TimeTicks::IsHighResolutionClockWorking() {
|
| +bool DefaultPlatform::TimeTicksHasHighRes() {
|
| return true;
|
| }
|
|
|
|
|