5#ifndef V8_BASE_PLATFORM_TIME_H_
6#define V8_BASE_PLATFORM_TIME_H_
37namespace time_internal {
38template<
class TimeClass>
76 return TimeDelta(hours * TimeConstants::kMicrosecondsPerHour);
79 return TimeDelta(minutes * TimeConstants::kMicrosecondsPerMinute);
82 return TimeDelta(seconds * TimeConstants::kMicrosecondsPerSecond);
85 return TimeDelta(milliseconds * TimeConstants::kMicrosecondsPerMillisecond);
95 return FromDouble(seconds * TimeConstants::kMicrosecondsPerSecond);
98 return FromDouble(milliseconds *
99 TimeConstants::kMicrosecondsPerMillisecond);
113 constexpr bool IsZero()
const {
return delta_ == 0; }
117 return delta_ == std::numeric_limits<int64_t>::max();
120 return delta_ == std::numeric_limits<int64_t>::min();
130 int InMinutes()
const;
131 double InSecondsF()
const;
132 int64_t InSeconds()
const;
133 double InMillisecondsF()
const;
134 int64_t InMilliseconds()
const;
135 int64_t InMillisecondsRoundedUp()
const;
136 int64_t InMicroseconds()
const;
137 int64_t InNanoseconds()
const;
141 struct mach_timespec ToMachTimespec() const;
145 struct timespec ToTimespec() const;
166 return static_cast<double>(delta_) /
static_cast<double>(other.delta_);
169 return TimesOf(other) * 100.0;
189 return delta_ / other.delta_;
194 return delta_ == other.delta_;
197 return delta_ != other.delta_;
200 return delta_ < other.delta_;
203 return delta_ <= other.delta_;
206 return delta_ > other.delta_;
209 return delta_ >= other.delta_;
215 static constexpr inline TimeDelta FromDouble(
double value);
221 explicit constexpr TimeDelta(int64_t delta) : delta_(delta) {}
229 return TimeDelta(saturated_cast<int64_t>(value));
234 return TimeDelta(std::numeric_limits<int64_t>::max());
239 return TimeDelta(std::numeric_limits<int64_t>::min());
242namespace time_internal {
250template <
class TimeClass>
257 static constexpr int64_t kQPCOverflowThreshold = INT64_C(0x8637BD05AF7);
270 return TimeClass(std::numeric_limits<int64_t>::max());
273 return TimeClass(std::numeric_limits<int64_t>::min());
278 return us_ == std::numeric_limits<int64_t>::max();
281 return us_ == std::numeric_limits<int64_t>::min();
301 return *(
static_cast<TimeClass*
>(
this));
319 return static_cast<TimeClass&
>(*
this = (*
this + delta));
322 return static_cast<TimeClass&
>(*
this = (*
this - delta));
327 return us_ == other.us_;
330 return us_ != other.us_;
333 return us_ < other.us_;
336 return us_ <= other.us_;
339 return us_ > other.us_;
342 return us_ >= other.us_;
370 constexpr Time() : TimeBase(0) {}
388 struct timespec ToTimespec() const;
392 struct timeval ToTimeval() const;
396 struct _FILETIME ToFiletime() const;
400 static Time FromJsTime(
double ms_since_epoch);
401 double ToJsTime()
const;
405 explicit constexpr Time(int64_t us) : TimeBase(us) {}
438 static bool IsHighResolution();
441 return TimeTicks(ticks * kMicrosecondsPerMillisecond);
449 explicit constexpr TimeTicks(int64_t ticks) : TimeBase(ticks) {}
453 return ticks + delta;
467 static bool IsSupported();
473 WaitUntilInitializedWin();
494 template <
class TimeClass>
499 explicit constexpr ThreadTicks(int64_t ticks) : TimeBase(ticks) {}
502#if V8_HOST_ARCH_ARM64
509 static double TSCTicksPerSecond();
511 static bool IsSupportedWin();
512 static void WaitUntilInitializedWin();
constexpr ThreadTicks(int64_t ticks)
static void WaitUntilInitialized()
static constexpr int64_t kMicrosecondsPerMinute
static constexpr int64_t kMicrosecondsPerWeek
static constexpr int64_t kMillisecondsPerDay
static constexpr int64_t kNanosecondsPerSecond
static constexpr int64_t kNanosecondsPerMicrosecond
static constexpr int64_t kMicrosecondsPerHour
static constexpr int64_t kMicrosecondsPerMillisecond
static constexpr int64_t kMicrosecondsPerSecond
static constexpr int64_t kMillisecondsPerSecond
static constexpr int64_t kHoursPerDay
static constexpr int64_t kMicrosecondsPerDay
static constexpr TimeDelta FromNanoseconds(int64_t nanoseconds)
static constexpr TimeDelta FromMinutes(int minutes)
TimeDelta operator*(int64_t a) const
static constexpr TimeDelta Max()
static constexpr TimeDelta FromMicroseconds(int64_t microseconds)
constexpr bool operator<(const TimeDelta &other) const
constexpr bool operator==(const TimeDelta &other) const
static constexpr TimeDelta FromMillisecondsD(double milliseconds)
static constexpr TimeDelta FromSeconds(int64_t seconds)
constexpr TimeDelta & operator-=(const TimeDelta &other)
static constexpr TimeDelta Min()
constexpr TimeDelta operator+(const TimeDelta &other) const
constexpr TimeDelta & operator+=(const TimeDelta &other)
constexpr bool IsZero() const
static constexpr TimeDelta FromSecondsD(double seconds)
static constexpr TimeDelta FromHours(int hours)
static constexpr TimeDelta FromDouble(double value)
static constexpr TimeDelta FromDays(int days)
TimeDelta operator/(int64_t a) const
constexpr TimeDelta operator-(const TimeDelta &other) const
constexpr bool operator<=(const TimeDelta &other) const
friend void swap(TimeDelta a, TimeDelta b)
int64_t operator/(const TimeDelta &other) const
constexpr TimeDelta operator-() const
static TimeDelta FromTimespec(struct timespec ts)
TimeDelta & operator*=(int64_t a)
constexpr TimeDelta(int64_t delta)
constexpr bool operator>(const TimeDelta &other) const
constexpr bool IsMax() const
static TimeDelta FromMachTimespec(struct mach_timespec ts)
double TimesOf(const TimeDelta &other) const
double PercentOf(const TimeDelta &other) const
static constexpr TimeDelta FromMilliseconds(int64_t milliseconds)
TimeDelta & operator/=(int64_t a)
constexpr bool IsMin() const
constexpr bool operator!=(const TimeDelta &other) const
constexpr bool operator>=(const TimeDelta &other) const
static constexpr TimeTicks FromMsTicksForTesting(int64_t ticks)
constexpr TimeTicks(int64_t ticks)
static Time FromTimespec(struct timespec ts)
constexpr Time(int64_t us)
static Time NowFromSystemTime()
static Time FromFiletime(struct _FILETIME ft)
static Time FromTimeval(struct timeval tv)
TimeClass & operator=(TimeClass other)
TimeClass & operator-=(TimeDelta delta)
bool operator>(const TimeBase< TimeClass > &other) const
bool operator>=(const TimeBase< TimeClass > &other) const
int64_t ToInternalValue() const
constexpr bool IsMin() const
TimeClass operator+(TimeDelta delta) const
bool operator==(const TimeBase< TimeClass > &other) const
TimeDelta operator-(TimeClass other) const
TimeClass operator-(TimeDelta delta) const
constexpr TimeBase(int64_t us)
constexpr bool IsMax() const
static TimeClass FromInternalValue(int64_t us)
bool operator!=(const TimeBase< TimeClass > &other) const
bool operator<=(const TimeBase< TimeClass > &other) const
constexpr bool IsNull() const
bool operator<(const TimeBase< TimeClass > &other) const
TimeClass & operator+=(TimeDelta delta)
constexpr TimeDelta since_origin() const
std::optional< TNode< JSArray > > a
int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs)
int64_t SignedSaturatedAdd64(int64_t lhs, int64_t rhs)
Time operator+(const TimeDelta &delta, const Time &time)
std::ostream & operator<<(std::ostream &out, AddressRegion region)