// Copyright 2013 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_BASE_PLATFORM_TIME_H_ #define V8_BASE_PLATFORM_TIME_H_ #include <stdint.h> #include <ctime> #include <iosfwd> #include <limits> #include "src/base/base-export.h" #include "src/base/bits.h" #include "src/base/macros.h" #include "src/base/safe_conversions.h" #if V8_OS_WIN #include "src/base/win32-headers.h" #endif // Forward declarations. extern "C" { struct _FILETIME; struct mach_timespec; struct timespec; struct timeval; } namespace v8 { namespace base { class Time; class TimeDelta; class TimeTicks; namespace time_internal { template<class TimeClass> class TimeBase; } // namespace time_internal class TimeConstants { … }; // ----------------------------------------------------------------------------- // TimeDelta // // This class represents a duration of time, internally represented in // microseonds. class V8_BASE_EXPORT TimeDelta final { … }; // static constexpr TimeDelta TimeDelta::FromDouble(double value) { … } // static constexpr TimeDelta TimeDelta::Max() { … } // static constexpr TimeDelta TimeDelta::Min() { … } namespace time_internal { // TimeBase-------------------------------------------------------------------- // Provides value storage and comparison/math operations common to all time // classes. Each subclass provides for strong type-checking to ensure // semantically meaningful comparison/math of time values from the same clock // source or timeline. template <class TimeClass> class TimeBase : public TimeConstants { … }; } // namespace time_internal // ----------------------------------------------------------------------------- // Time // // This class represents an absolute point in time, internally represented as // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970. class V8_BASE_EXPORT Time final : public time_internal::TimeBase<Time> { … }; V8_BASE_EXPORT std::ostream& operator<<(std::ostream&, const Time&); inline Time operator+(const TimeDelta& delta, const Time& time) { … } // ----------------------------------------------------------------------------- // TimeTicks // // This class represents an abstract time that is most of the time incrementing // for use in measuring time durations. It is internally represented in // microseconds. It can not be converted to a human-readable time, but is // guaranteed not to decrease (if the user changes the computer clock, // Time::Now() may actually decrease or jump). But note that TimeTicks may // "stand still", for example if the computer suspended. class V8_BASE_EXPORT TimeTicks final : public time_internal::TimeBase<TimeTicks> { … }; inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) { … } // ThreadTicks ---------------------------------------------------------------- // Represents a clock, specific to a particular thread, than runs only while the // thread is running. class V8_BASE_EXPORT ThreadTicks final : public time_internal::TimeBase<ThreadTicks> { … }; } // namespace base } // namespace v8 #endif // V8_BASE_PLATFORM_TIME_H_