12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127 |
- #ifndef BASE_TIME_TIME_H_
- #define BASE_TIME_TIME_H_
- #include <stdint.h>
- #include <time.h>
- #include <iosfwd>
- #include <limits>
- #include "base/base_export.h"
- #include "base/check_op.h"
- #include "base/compiler_specific.h"
- #include "base/numerics/safe_math.h"
- #include "base/optional.h"
- #include "base/strings/string_piece.h"
- #include "build/build_config.h"
- #if defined(OS_FUCHSIA)
- #include <zircon/types.h>
- #endif
- #if defined(OS_APPLE)
- #include <CoreFoundation/CoreFoundation.h>
- #undef TYPE_BOOL
- #endif
- #if defined(OS_ANDROID)
- #include <jni.h>
- #endif
- #if defined(OS_POSIX) || defined(OS_FUCHSIA)
- #include <unistd.h>
- #include <sys/time.h>
- #endif
- #if defined(OS_WIN)
- #include "base/gtest_prod_util.h"
- #include "base/win/windows_types.h"
- namespace ABI {
- namespace Windows {
- namespace Foundation {
- struct DateTime;
- }
- }
- }
- #endif
- namespace base {
- class PlatformThreadHandle;
- class BASE_EXPORT TimeDelta {
- public:
- constexpr TimeDelta() = default;
-
-
-
-
-
-
- static constexpr TimeDelta FromDays(int days);
- static constexpr TimeDelta FromHours(int hours);
- static constexpr TimeDelta FromMinutes(int minutes);
- static constexpr TimeDelta FromSecondsD(double secs);
- static constexpr TimeDelta FromSeconds(int64_t secs);
- static constexpr TimeDelta FromMillisecondsD(double ms);
- static constexpr TimeDelta FromMilliseconds(int64_t ms);
- static constexpr TimeDelta FromMicrosecondsD(double us);
- static constexpr TimeDelta FromMicroseconds(int64_t us);
- static constexpr TimeDelta FromNanosecondsD(double ns);
- static constexpr TimeDelta FromNanoseconds(int64_t ns);
- #if defined(OS_WIN)
- static TimeDelta FromQPCValue(LONGLONG qpc_value);
-
-
- static TimeDelta FromFileTime(FILETIME ft);
- static TimeDelta FromWinrtDateTime(ABI::Windows::Foundation::DateTime dt);
- #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
- static TimeDelta FromTimeSpec(const timespec& ts);
- #endif
- #if defined(OS_FUCHSIA)
- static TimeDelta FromZxDuration(zx_duration_t nanos);
- #endif
- #if defined(OS_MAC)
- static TimeDelta FromMachTime(uint64_t mach_time);
- #endif
-
- static constexpr TimeDelta FromHz(double frequency);
-
-
-
-
-
-
-
-
-
-
-
-
-
- static Optional<TimeDelta> FromString(StringPiece duration_string);
-
-
-
-
-
-
- static constexpr TimeDelta FromInternalValue(int64_t delta) {
- return TimeDelta(delta);
- }
-
-
-
- static constexpr TimeDelta Max();
-
-
-
- static constexpr TimeDelta Min();
-
-
-
-
-
-
- constexpr int64_t ToInternalValue() const { return delta_; }
-
- constexpr TimeDelta magnitude() const {
-
- if (is_min())
- return Max();
-
-
- const int64_t mask = delta_ >> (sizeof(delta_) * 8 - 1);
- return TimeDelta((delta_ + mask) ^ mask);
- }
-
- constexpr bool is_zero() const { return delta_ == 0; }
-
- constexpr bool is_max() const { return *this == Max(); }
- constexpr bool is_min() const { return *this == Min(); }
- constexpr bool is_inf() const { return is_min() || is_max(); }
- #if defined(OS_POSIX) || defined(OS_FUCHSIA)
- struct timespec ToTimeSpec() const;
- #endif
- #if defined(OS_FUCHSIA)
- zx_duration_t ToZxDuration() const;
- #endif
- #if defined(OS_WIN)
- ABI::Windows::Foundation::DateTime ToWinrtDateTime() const;
- #endif
-
-
- constexpr double ToHz() const { return FromSeconds(1) / *this; }
-
-
-
-
-
-
-
-
-
-
- int InDays() const;
- int InDaysFloored() const;
- constexpr int InHours() const;
- constexpr int InMinutes() const;
- double InSecondsF() const;
- int64_t InSeconds() const;
- double InMillisecondsF() const;
- int64_t InMilliseconds() const;
- int64_t InMillisecondsRoundedUp() const;
- constexpr int64_t InMicroseconds() const { return delta_; }
- double InMicrosecondsF() const;
- constexpr int64_t InNanoseconds() const;
-
- constexpr TimeDelta operator+(TimeDelta other) const;
- constexpr TimeDelta operator-(TimeDelta other) const;
- constexpr TimeDelta& operator+=(TimeDelta other) {
- return *this = (*this + other);
- }
- constexpr TimeDelta& operator-=(TimeDelta other) {
- return *this = (*this - other);
- }
- constexpr TimeDelta operator-() const {
- if (!is_inf())
- return TimeDelta(-delta_);
- return (delta_ < 0) ? Max() : Min();
- }
-
- template <typename T>
- constexpr TimeDelta operator*(T a) const {
- CheckedNumeric<int64_t> rv(delta_);
- rv *= a;
- if (rv.IsValid())
- return TimeDelta(rv.ValueOrDie());
- return ((delta_ < 0) == (a < 0)) ? Max() : Min();
- }
- template <typename T>
- constexpr TimeDelta operator/(T a) const {
- CheckedNumeric<int64_t> rv(delta_);
- rv /= a;
- if (rv.IsValid())
- return TimeDelta(rv.ValueOrDie());
- return ((delta_ < 0) == (a < 0)) ? Max() : Min();
- }
- template <typename T>
- constexpr TimeDelta& operator*=(T a) {
- return *this = (*this * a);
- }
- template <typename T>
- constexpr TimeDelta& operator/=(T a) {
- return *this = (*this / a);
- }
-
-
-
-
- constexpr double operator/(TimeDelta a) const {
-
-
-
-
- CHECK((!is_zero() || !a.is_zero()) && (!is_inf() || !a.is_inf()));
- return ToDouble() / a.ToDouble();
- }
- constexpr int64_t IntDiv(TimeDelta a) const {
- if (!is_inf() && !a.is_zero())
- return delta_ / a.delta_;
-
-
- CHECK((!is_zero() || !a.is_zero()) && (!is_inf() || !a.is_inf()));
- return ((delta_ < 0) == (a.delta_ < 0))
- ? std::numeric_limits<int64_t>::max()
- : std::numeric_limits<int64_t>::min();
- }
- constexpr TimeDelta operator%(TimeDelta a) const {
- return TimeDelta(
- (is_inf() || a.is_zero() || a.is_inf()) ? delta_ : (delta_ % a.delta_));
- }
- TimeDelta& operator%=(TimeDelta other) { return *this = (*this % other); }
-
- constexpr bool operator==(TimeDelta other) const {
- return delta_ == other.delta_;
- }
- constexpr bool operator!=(TimeDelta other) const {
- return delta_ != other.delta_;
- }
- constexpr bool operator<(TimeDelta other) const {
- return delta_ < other.delta_;
- }
- constexpr bool operator<=(TimeDelta other) const {
- return delta_ <= other.delta_;
- }
- constexpr bool operator>(TimeDelta other) const {
- return delta_ > other.delta_;
- }
- constexpr bool operator>=(TimeDelta other) const {
- return delta_ >= other.delta_;
- }
-
-
- TimeDelta CeilToMultiple(TimeDelta interval) const;
- TimeDelta FloorToMultiple(TimeDelta interval) const;
- TimeDelta RoundToMultiple(TimeDelta interval) const;
- private:
-
-
-
- constexpr explicit TimeDelta(int64_t delta_us) : delta_(delta_us) {}
-
-
- constexpr double ToDouble() const {
- if (!is_inf())
- return static_cast<double>(delta_);
- return (delta_ < 0) ? -std::numeric_limits<double>::infinity()
- : std::numeric_limits<double>::infinity();
- }
-
- int64_t delta_ = 0;
- };
- constexpr TimeDelta TimeDelta::operator+(TimeDelta other) const {
- if (!other.is_inf())
- return TimeDelta(int64_t{base::ClampAdd(delta_, other.delta_)});
-
- CHECK(!is_inf() || (delta_ == other.delta_));
- return other;
- }
- constexpr TimeDelta TimeDelta::operator-(TimeDelta other) const {
- if (!other.is_inf())
- return TimeDelta(int64_t{base::ClampSub(delta_, other.delta_)});
-
- CHECK_NE(delta_, other.delta_);
- return (other.delta_ < 0) ? Max() : Min();
- }
- template <typename T>
- constexpr TimeDelta operator*(T a, TimeDelta td) {
- return td * a;
- }
- BASE_EXPORT std::ostream& operator<<(std::ostream& os, TimeDelta time_delta);
- namespace time_internal {
- template<class TimeClass>
- class TimeBase {
- public:
- static constexpr int64_t kHoursPerDay = 24;
- static constexpr int64_t kSecondsPerMinute = 60;
- static constexpr int64_t kMinutesPerHour = 60;
- static constexpr int64_t kSecondsPerHour =
- kSecondsPerMinute * kMinutesPerHour;
- static constexpr int64_t kMillisecondsPerSecond = 1000;
- static constexpr int64_t kMillisecondsPerDay =
- kMillisecondsPerSecond * kSecondsPerHour * kHoursPerDay;
- static constexpr int64_t kMicrosecondsPerMillisecond = 1000;
- static constexpr int64_t kMicrosecondsPerSecond =
- kMicrosecondsPerMillisecond * kMillisecondsPerSecond;
- static constexpr int64_t kMicrosecondsPerMinute =
- kMicrosecondsPerSecond * kSecondsPerMinute;
- static constexpr int64_t kMicrosecondsPerHour =
- kMicrosecondsPerMinute * kMinutesPerHour;
- static constexpr int64_t kMicrosecondsPerDay =
- kMicrosecondsPerHour * kHoursPerDay;
- static constexpr int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7;
- static constexpr int64_t kNanosecondsPerMicrosecond = 1000;
- static constexpr int64_t kNanosecondsPerSecond =
- kNanosecondsPerMicrosecond * kMicrosecondsPerSecond;
-
-
-
-
-
- constexpr bool is_null() const { return us_ == 0; }
-
- constexpr bool is_max() const { return *this == Max(); }
- constexpr bool is_min() const { return *this == Min(); }
- constexpr bool is_inf() const { return is_min() || is_max(); }
-
-
- static constexpr TimeClass Max() {
- return TimeClass(std::numeric_limits<int64_t>::max());
- }
- static constexpr TimeClass Min() {
- return TimeClass(std::numeric_limits<int64_t>::min());
- }
-
-
-
-
-
-
- constexpr int64_t ToInternalValue() const { return us_; }
-
-
-
-
-
-
- constexpr TimeDelta since_origin() const {
- return TimeDelta::FromMicroseconds(us_);
- }
- constexpr TimeClass& operator=(TimeClass other) {
- us_ = other.us_;
- return *(static_cast<TimeClass*>(this));
- }
-
- constexpr TimeDelta operator-(TimeClass other) const {
- return TimeDelta::FromMicroseconds(us_ - other.us_);
- }
-
- constexpr TimeClass operator+(TimeDelta delta) const {
- return TimeClass(
- (TimeDelta::FromMicroseconds(us_) + delta).InMicroseconds());
- }
- constexpr TimeClass operator-(TimeDelta delta) const {
- return TimeClass(
- (TimeDelta::FromMicroseconds(us_) - delta).InMicroseconds());
- }
-
- constexpr TimeClass& operator+=(TimeDelta delta) {
- return static_cast<TimeClass&>(*this = (*this + delta));
- }
- constexpr TimeClass& operator-=(TimeDelta delta) {
- return static_cast<TimeClass&>(*this = (*this - delta));
- }
-
- constexpr bool operator==(TimeClass other) const { return us_ == other.us_; }
- constexpr bool operator!=(TimeClass other) const { return us_ != other.us_; }
- constexpr bool operator<(TimeClass other) const { return us_ < other.us_; }
- constexpr bool operator<=(TimeClass other) const { return us_ <= other.us_; }
- constexpr bool operator>(TimeClass other) const { return us_ > other.us_; }
- constexpr bool operator>=(TimeClass other) const { return us_ >= other.us_; }
- protected:
- constexpr explicit TimeBase(int64_t us) : us_(us) {}
-
- int64_t us_;
- };
- }
- template <class TimeClass>
- inline constexpr TimeClass operator+(TimeDelta delta, TimeClass t) {
- return t + delta;
- }
- class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
- public:
-
-
-
-
-
- static constexpr int64_t kTimeTToMicrosecondsOffset =
- INT64_C(11644473600000000);
- #if defined(OS_WIN)
-
-
-
- static constexpr int64_t kQPCOverflowThreshold = INT64_C(0x8637BD05AF7);
- #endif
- #if defined(OS_WIN)
- static constexpr int kExplodedMinYear = 1601;
- static constexpr int kExplodedMaxYear = 30827;
- #elif defined(OS_IOS) && !__LP64__
- static constexpr int kExplodedMinYear = std::numeric_limits<int>::min();
- static constexpr int kExplodedMaxYear = std::numeric_limits<int>::max();
- #elif defined(OS_APPLE)
- static constexpr int kExplodedMinYear = 1902;
- static constexpr int kExplodedMaxYear = std::numeric_limits<int>::max();
- #elif defined(OS_ANDROID)
-
-
-
- static constexpr int kExplodedMinYear = 1902;
- static constexpr int kExplodedMaxYear = std::numeric_limits<int>::max();
- #else
- static constexpr int kExplodedMinYear =
- (sizeof(time_t) == 4 ? 1902 : std::numeric_limits<int>::min());
- static constexpr int kExplodedMaxYear =
- (sizeof(time_t) == 4 ? 2037 : std::numeric_limits<int>::max());
- #endif
-
-
-
- struct BASE_EXPORT Exploded {
- int year;
- int month;
- int day_of_week;
- int day_of_month;
- int hour;
- int minute;
- int second;
-
- int millisecond;
-
-
-
- bool HasValidValues() const;
- };
-
- constexpr Time() : TimeBase(0) {}
-
- static Time UnixEpoch();
-
-
-
- static Time Now();
-
-
-
-
- static Time NowFromSystemTime();
-
-
-
-
-
-
-
-
-
-
-
- static Time FromDeltaSinceWindowsEpoch(TimeDelta delta);
- TimeDelta ToDeltaSinceWindowsEpoch() const;
-
- static Time FromTimeT(time_t tt);
- time_t ToTimeT() const;
-
-
-
-
-
- static Time FromDoubleT(double dt);
- double ToDoubleT() const;
- #if defined(OS_POSIX) || defined(OS_FUCHSIA)
-
-
-
-
- static Time FromTimeSpec(const timespec& ts);
- #endif
-
-
-
-
-
-
-
-
- static Time FromJsTime(double ms_since_epoch);
- double ToJsTime() const;
- double ToJsTimeIgnoringNull() const;
-
-
-
- static Time FromJavaTime(int64_t ms_since_epoch);
- int64_t ToJavaTime() const;
- #if defined(OS_POSIX) || defined(OS_FUCHSIA)
- static Time FromTimeVal(struct timeval t);
- struct timeval ToTimeVal() const;
- #endif
- #if defined(OS_FUCHSIA)
- static Time FromZxTime(zx_time_t time);
- zx_time_t ToZxTime() const;
- #endif
- #if defined(OS_APPLE)
- static Time FromCFAbsoluteTime(CFAbsoluteTime t);
- CFAbsoluteTime ToCFAbsoluteTime() const;
- #endif
- #if defined(OS_WIN)
- static Time FromFileTime(FILETIME ft);
- FILETIME ToFileTime() const;
-
-
-
- static const int kMinLowResolutionThresholdMs = 16;
-
- static void EnableHighResolutionTimer(bool enable);
-
-
-
-
-
-
-
- static bool ActivateHighResolutionTimer(bool activate);
-
-
-
- static bool IsHighResolutionTimerInUse();
-
-
-
-
-
-
-
-
-
- static void ResetHighResolutionTimerUsage();
- static double GetHighResolutionTimerUsage();
- #endif
-
-
-
- static bool FromUTCExploded(const Exploded& exploded,
- Time* time) WARN_UNUSED_RESULT {
- return FromExploded(false, exploded, time);
- }
- static bool FromLocalExploded(const Exploded& exploded,
- Time* time) WARN_UNUSED_RESULT {
- return FromExploded(true, exploded, time);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- static bool FromString(const char* time_string,
- Time* parsed_time) WARN_UNUSED_RESULT {
- return FromStringInternal(time_string, true, parsed_time);
- }
- static bool FromUTCString(const char* time_string,
- Time* parsed_time) WARN_UNUSED_RESULT {
- return FromStringInternal(time_string, false, parsed_time);
- }
-
-
-
-
-
-
-
-
- void UTCExplode(Exploded* exploded) const { Explode(false, exploded); }
- void LocalExplode(Exploded* exploded) const { Explode(true, exploded); }
-
-
- Time UTCMidnight() const { return Midnight(false); }
- Time LocalMidnight() const { return Midnight(true); }
-
-
-
-
-
-
-
- static constexpr Time FromInternalValue(int64_t us) { return Time(us); }
- private:
- friend class time_internal::TimeBase<Time>;
- constexpr explicit Time(int64_t microseconds_since_win_epoch)
- : TimeBase(microseconds_since_win_epoch) {}
-
-
- void Explode(bool is_local, Exploded* exploded) const;
-
-
-
-
- static bool FromExploded(bool is_local,
- const Exploded& exploded,
- Time* time) WARN_UNUSED_RESULT;
-
-
- static void ExplodeUsingIcu(int64_t millis_since_unix_epoch,
- bool is_local,
- Exploded* exploded);
- static bool FromExplodedUsingIcu(bool is_local,
- const Exploded& exploded,
- int64_t* millis_since_unix_epoch)
- WARN_UNUSED_RESULT;
-
-
- Time Midnight(bool is_local) const;
-
-
-
-
-
-
-
- static bool FromStringInternal(const char* time_string,
- bool is_local,
- Time* parsed_time) WARN_UNUSED_RESULT;
-
- static bool ExplodedMostlyEquals(const Exploded& lhs,
- const Exploded& rhs) WARN_UNUSED_RESULT;
-
-
- static bool FromMillisecondsSinceUnixEpoch(int64_t unix_milliseconds,
- Time* time) WARN_UNUSED_RESULT;
-
-
- int64_t ToRoundedDownMillisecondsSinceUnixEpoch() const;
- };
- constexpr TimeDelta TimeDelta::FromDays(int days) {
- return (days == std::numeric_limits<int>::max())
- ? Max()
- : TimeDelta(days * Time::kMicrosecondsPerDay);
- }
- constexpr TimeDelta TimeDelta::FromHours(int hours) {
- return (hours == std::numeric_limits<int>::max())
- ? Max()
- : TimeDelta(hours * Time::kMicrosecondsPerHour);
- }
- constexpr TimeDelta TimeDelta::FromMinutes(int minutes) {
- return (minutes == std::numeric_limits<int>::max())
- ? Max()
- : TimeDelta(minutes * Time::kMicrosecondsPerMinute);
- }
- constexpr TimeDelta TimeDelta::FromSecondsD(double secs) {
- return TimeDelta(
- saturated_cast<int64_t>(secs * Time::kMicrosecondsPerSecond));
- }
- constexpr TimeDelta TimeDelta::FromSeconds(int64_t secs) {
- return TimeDelta(int64_t{base::ClampMul(secs, Time::kMicrosecondsPerSecond)});
- }
- constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) {
- return TimeDelta(
- saturated_cast<int64_t>(ms * Time::kMicrosecondsPerMillisecond));
- }
- constexpr TimeDelta TimeDelta::FromMilliseconds(int64_t ms) {
- return TimeDelta(
- int64_t{base::ClampMul(ms, Time::kMicrosecondsPerMillisecond)});
- }
- constexpr TimeDelta TimeDelta::FromMicrosecondsD(double us) {
- return TimeDelta(saturated_cast<int64_t>(us));
- }
- constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) {
- return TimeDelta(us);
- }
- constexpr TimeDelta TimeDelta::FromNanosecondsD(double ns) {
- return TimeDelta(
- saturated_cast<int64_t>(ns / Time::kNanosecondsPerMicrosecond));
- }
- constexpr TimeDelta TimeDelta::FromNanoseconds(int64_t ns) {
- return TimeDelta(ns / Time::kNanosecondsPerMicrosecond);
- }
- constexpr TimeDelta TimeDelta::FromHz(double frequency) {
- return FromSeconds(1) / frequency;
- }
- constexpr int TimeDelta::InHours() const {
-
-
- return saturated_cast<int>(delta_ / Time::kMicrosecondsPerHour);
- }
- constexpr int TimeDelta::InMinutes() const {
-
-
- return saturated_cast<int>(delta_ / Time::kMicrosecondsPerMinute);
- }
- constexpr int64_t TimeDelta::InNanoseconds() const {
- return base::ClampMul(delta_, Time::kNanosecondsPerMicrosecond);
- }
- constexpr TimeDelta TimeDelta::Max() {
- return TimeDelta(std::numeric_limits<int64_t>::max());
- }
- constexpr TimeDelta TimeDelta::Min() {
- return TimeDelta(std::numeric_limits<int64_t>::min());
- }
- BASE_EXPORT std::ostream& operator<<(std::ostream& os, Time time);
- class BASE_EXPORT TimeTicks : public time_internal::TimeBase<TimeTicks> {
- public:
-
- enum class Clock {
- FUCHSIA_ZX_CLOCK_MONOTONIC,
- LINUX_CLOCK_MONOTONIC,
- IOS_CF_ABSOLUTE_TIME_MINUS_KERN_BOOTTIME,
- MAC_MACH_ABSOLUTE_TIME,
- WIN_QPC,
- WIN_ROLLOVER_PROTECTED_TIME_GET_TIME
- };
- constexpr TimeTicks() : TimeBase(0) {}
-
-
-
-
- static TimeTicks Now();
-
-
-
-
- static bool IsHighResolution() WARN_UNUSED_RESULT;
-
-
-
-
-
- static bool IsConsistentAcrossProcesses() WARN_UNUSED_RESULT;
- #if defined(OS_FUCHSIA)
-
- static TimeTicks FromZxTime(zx_time_t nanos_since_boot);
- zx_time_t ToZxTime() const;
- #endif
- #if defined(OS_WIN)
-
-
-
- static TimeTicks FromQPCValue(LONGLONG qpc_value);
- #endif
- #if defined(OS_MAC)
- static TimeTicks FromMachAbsoluteTime(uint64_t mach_absolute_time);
- #endif
- #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
-
-
-
-
- static TimeTicks FromUptimeMillis(int64_t uptime_millis_value);
- #endif
-
-
-
-
-
-
-
-
- static TimeTicks UnixEpoch();
-
-
-
- TimeTicks SnappedToNextTick(TimeTicks tick_phase,
- TimeDelta tick_interval) const;
-
-
-
- static Clock GetClock();
-
-
-
-
-
-
-
- static constexpr TimeTicks FromInternalValue(int64_t us) {
- return TimeTicks(us);
- }
- protected:
- #if defined(OS_WIN)
- typedef DWORD (*TickFunctionType)(void);
- static TickFunctionType SetMockTickFunction(TickFunctionType ticker);
- #endif
- private:
- friend class time_internal::TimeBase<TimeTicks>;
-
-
- constexpr explicit TimeTicks(int64_t us) : TimeBase(us) {}
- };
- BASE_EXPORT std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks);
- class BASE_EXPORT ThreadTicks : public time_internal::TimeBase<ThreadTicks> {
- public:
- constexpr ThreadTicks() : TimeBase(0) {}
-
- static bool IsSupported() WARN_UNUSED_RESULT {
- #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \
- defined(OS_MAC) || defined(OS_ANDROID) || defined(OS_FUCHSIA)
- return true;
- #elif defined(OS_WIN)
- return IsSupportedWin();
- #else
- return false;
- #endif
- }
-
-
- static void WaitUntilInitialized() {
- #if defined(OS_WIN)
- WaitUntilInitializedWin();
- #endif
- }
-
-
-
-
-
-
-
- static ThreadTicks Now();
- #if defined(OS_WIN)
-
-
-
- static ThreadTicks GetForThread(const PlatformThreadHandle& thread_handle);
- #endif
-
-
-
-
-
-
-
- static constexpr ThreadTicks FromInternalValue(int64_t us) {
- return ThreadTicks(us);
- }
- private:
- friend class time_internal::TimeBase<ThreadTicks>;
-
-
- constexpr explicit ThreadTicks(int64_t us) : TimeBase(us) {}
- #if defined(OS_WIN)
- FRIEND_TEST_ALL_PREFIXES(TimeTicks, TSCTicksPerSecond);
- #if defined(ARCH_CPU_ARM64)
-
-
-
- #else
-
-
-
-
- static double TSCTicksPerSecond();
- #endif
- static bool IsSupportedWin() WARN_UNUSED_RESULT;
- static void WaitUntilInitializedWin();
- #endif
- };
- BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks);
- }
- #endif
|