Index: src/platform/time.cc |
diff --git a/src/platform/time.cc b/src/platform/time.cc |
index 073ca1e1f4b985d792d9a2894155d7dd93b07831..756be9375a82f9feb1e6aa785f909fdba88886ff 100644 |
--- a/src/platform/time.cc |
+++ b/src/platform/time.cc |
@@ -123,6 +123,27 @@ int64_t TimeDelta::InNanoseconds() const { |
} |
+#if V8_OS_MACOSX |
+ |
+TimeDelta TimeDelta::FromMachTimespec(struct mach_timespec ts) { |
+ ASSERT(ts.tv_nsec >= 0); |
+ 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_WIN |
// We implement time using the high-resolution timers so that we can get |
@@ -246,6 +267,39 @@ Time Time::NowFromSystemTime() { |
} |
+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; |
+} |
+ |
+ |
Time Time::FromTimeval(struct timeval tv) { |
ASSERT(tv.tv_usec >= 0); |
ASSERT(tv.tv_usec < static_cast<suseconds_t>(kMicrosecondsPerSecond)); |