| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/base/platform/time.h" | 5 #include "src/base/platform/time.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX | 7 #if V8_OS_POSIX |
| 8 #include <fcntl.h> // for O_RDONLY | 8 #include <fcntl.h> // for O_RDONLY |
| 9 #include <sys/time.h> | 9 #include <sys/time.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 DCHECK_GE(ts.tv_nsec, 0); | 126 DCHECK_GE(ts.tv_nsec, 0); |
| 127 DCHECK_LT(ts.tv_nsec, | 127 DCHECK_LT(ts.tv_nsec, |
| 128 static_cast<long>(Time::kNanosecondsPerSecond)); // NOLINT | 128 static_cast<long>(Time::kNanosecondsPerSecond)); // NOLINT |
| 129 return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond + | 129 return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond + |
| 130 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); | 130 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
| 131 } | 131 } |
| 132 | 132 |
| 133 | 133 |
| 134 struct timespec TimeDelta::ToTimespec() const { | 134 struct timespec TimeDelta::ToTimespec() const { |
| 135 struct timespec ts; | 135 struct timespec ts; |
| 136 ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond; | 136 ts.tv_sec = static_cast<time_t>(delta_ / Time::kMicrosecondsPerSecond); |
| 137 ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) * | 137 ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) * |
| 138 Time::kNanosecondsPerMicrosecond; | 138 Time::kNanosecondsPerMicrosecond; |
| 139 return ts; | 139 return ts; |
| 140 } | 140 } |
| 141 | 141 |
| 142 #endif // V8_OS_POSIX | 142 #endif // V8_OS_POSIX |
| 143 | 143 |
| 144 | 144 |
| 145 #if V8_OS_WIN | 145 #if V8_OS_WIN |
| 146 | 146 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (IsNull()) { | 285 if (IsNull()) { |
| 286 ts.tv_sec = 0; | 286 ts.tv_sec = 0; |
| 287 ts.tv_nsec = 0; | 287 ts.tv_nsec = 0; |
| 288 return ts; | 288 return ts; |
| 289 } | 289 } |
| 290 if (IsMax()) { | 290 if (IsMax()) { |
| 291 ts.tv_sec = std::numeric_limits<time_t>::max(); | 291 ts.tv_sec = std::numeric_limits<time_t>::max(); |
| 292 ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT | 292 ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT |
| 293 return ts; | 293 return ts; |
| 294 } | 294 } |
| 295 ts.tv_sec = us_ / kMicrosecondsPerSecond; | 295 ts.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond); |
| 296 ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond; | 296 ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond; |
| 297 return ts; | 297 return ts; |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 Time Time::FromTimeval(struct timeval tv) { | 301 Time Time::FromTimeval(struct timeval tv) { |
| 302 DCHECK(tv.tv_usec >= 0); | 302 DCHECK(tv.tv_usec >= 0); |
| 303 DCHECK(tv.tv_usec < static_cast<suseconds_t>(kMicrosecondsPerSecond)); | 303 DCHECK(tv.tv_usec < static_cast<suseconds_t>(kMicrosecondsPerSecond)); |
| 304 if (tv.tv_usec == 0 && tv.tv_sec == 0) { | 304 if (tv.tv_usec == 0 && tv.tv_sec == 0) { |
| 305 return Time(); | 305 return Time(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 317 if (IsNull()) { | 317 if (IsNull()) { |
| 318 tv.tv_sec = 0; | 318 tv.tv_sec = 0; |
| 319 tv.tv_usec = 0; | 319 tv.tv_usec = 0; |
| 320 return tv; | 320 return tv; |
| 321 } | 321 } |
| 322 if (IsMax()) { | 322 if (IsMax()) { |
| 323 tv.tv_sec = std::numeric_limits<time_t>::max(); | 323 tv.tv_sec = std::numeric_limits<time_t>::max(); |
| 324 tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1); | 324 tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1); |
| 325 return tv; | 325 return tv; |
| 326 } | 326 } |
| 327 tv.tv_sec = us_ / kMicrosecondsPerSecond; | 327 tv.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond); |
| 328 tv.tv_usec = us_ % kMicrosecondsPerSecond; | 328 tv.tv_usec = us_ % kMicrosecondsPerSecond; |
| 329 return tv; | 329 return tv; |
| 330 } | 330 } |
| 331 | 331 |
| 332 #endif // V8_OS_WIN | 332 #endif // V8_OS_WIN |
| 333 | 333 |
| 334 | 334 |
| 335 Time Time::FromJsTime(double ms_since_epoch) { | 335 Time Time::FromJsTime(double ms_since_epoch) { |
| 336 // The epoch is a valid time, so this constructor doesn't interpret | 336 // The epoch is a valid time, so this constructor doesn't interpret |
| 337 // 0 as the null time. | 337 // 0 as the null time. |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 638 |
| 639 | 639 |
| 640 // static | 640 // static |
| 641 bool TimeTicks::KernelTimestampAvailable() { | 641 bool TimeTicks::KernelTimestampAvailable() { |
| 642 return kernel_tick_clock.Pointer()->Available(); | 642 return kernel_tick_clock.Pointer()->Available(); |
| 643 } | 643 } |
| 644 | 644 |
| 645 #endif // V8_OS_WIN | 645 #endif // V8_OS_WIN |
| 646 | 646 |
| 647 } } // namespace v8::base | 647 } } // namespace v8::base |
| OLD | NEW |