| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 int64_t TimeDelta::InMilliseconds() const { | 116 int64_t TimeDelta::InMilliseconds() const { |
| 117 return delta_ / Time::kMicrosecondsPerMillisecond; | 117 return delta_ / Time::kMicrosecondsPerMillisecond; |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 int64_t TimeDelta::InNanoseconds() const { | 121 int64_t TimeDelta::InNanoseconds() const { |
| 122 return delta_ * Time::kNanosecondsPerMicrosecond; | 122 return delta_ * Time::kNanosecondsPerMicrosecond; |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 #if V8_OS_MACOSX |
| 127 |
| 128 TimeDelta TimeDelta::FromMachTimespec(struct mach_timespec ts) { |
| 129 ASSERT(ts.tv_nsec >= 0); |
| 130 return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond + |
| 131 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
| 132 } |
| 133 |
| 134 |
| 135 struct mach_timespec TimeDelta::ToMachTimespec() const { |
| 136 struct mach_timespec ts; |
| 137 ASSERT(delta_ >= 0); |
| 138 ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond; |
| 139 ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) * |
| 140 Time::kNanosecondsPerMicrosecond; |
| 141 return ts; |
| 142 } |
| 143 |
| 144 #endif // V8_OS_MACOSX |
| 145 |
| 146 |
| 126 #if V8_OS_WIN | 147 #if V8_OS_WIN |
| 127 | 148 |
| 128 // We implement time using the high-resolution timers so that we can get | 149 // We implement time using the high-resolution timers so that we can get |
| 129 // timeouts which are smaller than 10-15ms. To avoid any drift, we | 150 // timeouts which are smaller than 10-15ms. To avoid any drift, we |
| 130 // periodically resync the internal clock to the system clock. | 151 // periodically resync the internal clock to the system clock. |
| 131 class Clock V8_FINAL { | 152 class Clock V8_FINAL { |
| 132 public: | 153 public: |
| 133 Clock() : initial_time_(CurrentWallclockTime()), | 154 Clock() : initial_time_(CurrentWallclockTime()), |
| 134 initial_ticks_(TimeTicks::Now()) {} | 155 initial_ticks_(TimeTicks::Now()) {} |
| 135 | 156 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 USE(result); | 260 USE(result); |
| 240 return FromTimeval(tv); | 261 return FromTimeval(tv); |
| 241 } | 262 } |
| 242 | 263 |
| 243 | 264 |
| 244 Time Time::NowFromSystemTime() { | 265 Time Time::NowFromSystemTime() { |
| 245 return Now(); | 266 return Now(); |
| 246 } | 267 } |
| 247 | 268 |
| 248 | 269 |
| 270 Time Time::FromTimespec(struct timespec ts) { |
| 271 ASSERT(ts.tv_nsec >= 0); |
| 272 ASSERT(ts.tv_nsec < static_cast<long>(kNanosecondsPerSecond)); // NOLINT |
| 273 if (ts.tv_nsec == 0 && ts.tv_sec == 0) { |
| 274 return Time(); |
| 275 } |
| 276 if (ts.tv_nsec == static_cast<long>(kNanosecondsPerSecond - 1) && // NOLINT |
| 277 ts.tv_sec == std::numeric_limits<time_t>::max()) { |
| 278 return Max(); |
| 279 } |
| 280 return Time(ts.tv_sec * kMicrosecondsPerSecond + |
| 281 ts.tv_nsec / kNanosecondsPerMicrosecond); |
| 282 } |
| 283 |
| 284 |
| 285 struct timespec Time::ToTimespec() const { |
| 286 struct timespec ts; |
| 287 if (IsNull()) { |
| 288 ts.tv_sec = 0; |
| 289 ts.tv_nsec = 0; |
| 290 return ts; |
| 291 } |
| 292 if (IsMax()) { |
| 293 ts.tv_sec = std::numeric_limits<time_t>::max(); |
| 294 ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT |
| 295 return ts; |
| 296 } |
| 297 ts.tv_sec = us_ / kMicrosecondsPerSecond; |
| 298 ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond; |
| 299 return ts; |
| 300 } |
| 301 |
| 302 |
| 249 Time Time::FromTimeval(struct timeval tv) { | 303 Time Time::FromTimeval(struct timeval tv) { |
| 250 ASSERT(tv.tv_usec >= 0); | 304 ASSERT(tv.tv_usec >= 0); |
| 251 ASSERT(tv.tv_usec < static_cast<suseconds_t>(kMicrosecondsPerSecond)); | 305 ASSERT(tv.tv_usec < static_cast<suseconds_t>(kMicrosecondsPerSecond)); |
| 252 if (tv.tv_usec == 0 && tv.tv_sec == 0) { | 306 if (tv.tv_usec == 0 && tv.tv_sec == 0) { |
| 253 return Time(); | 307 return Time(); |
| 254 } | 308 } |
| 255 if (tv.tv_usec == static_cast<suseconds_t>(kMicrosecondsPerSecond - 1) && | 309 if (tv.tv_usec == static_cast<suseconds_t>(kMicrosecondsPerSecond - 1) && |
| 256 tv.tv_sec == std::numeric_limits<time_t>::max()) { | 310 tv.tv_sec == std::numeric_limits<time_t>::max()) { |
| 257 return Max(); | 311 return Max(); |
| 258 } | 312 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + | 580 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + |
| 527 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); | 581 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
| 528 #endif // V8_OS_MACOSX | 582 #endif // V8_OS_MACOSX |
| 529 // Make sure we never return 0 here. | 583 // Make sure we never return 0 here. |
| 530 return TimeTicks(ticks + 1); | 584 return TimeTicks(ticks + 1); |
| 531 } | 585 } |
| 532 | 586 |
| 533 #endif // V8_OS_WIN | 587 #endif // V8_OS_WIN |
| 534 | 588 |
| 535 } } // namespace v8::internal | 589 } } // namespace v8::internal |
| OLD | NEW |