| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 // Time represents an absolute point in coordinated universal time (UTC), | 5 // Time represents an absolute point in coordinated universal time (UTC), |
| 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch | 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch |
| 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are | 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are |
| 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump | 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump |
| 9 // around as the operating system makes adjustments to synchronize (e.g., with | 9 // around as the operating system makes adjustments to synchronize (e.g., with |
| 10 // NTP servers). Thus, client code that uses the Time class must account for | 10 // NTP servers). Thus, client code that uses the Time class must account for |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 static constexpr TimeDelta FromMinutes(int minutes); | 112 static constexpr TimeDelta FromMinutes(int minutes); |
| 113 static constexpr TimeDelta FromSeconds(int64_t secs); | 113 static constexpr TimeDelta FromSeconds(int64_t secs); |
| 114 static constexpr TimeDelta FromMilliseconds(int64_t ms); | 114 static constexpr TimeDelta FromMilliseconds(int64_t ms); |
| 115 static constexpr TimeDelta FromSecondsD(double secs); | 115 static constexpr TimeDelta FromSecondsD(double secs); |
| 116 static constexpr TimeDelta FromMillisecondsD(double ms); | 116 static constexpr TimeDelta FromMillisecondsD(double ms); |
| 117 static constexpr TimeDelta FromMicroseconds(int64_t us); | 117 static constexpr TimeDelta FromMicroseconds(int64_t us); |
| 118 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
| 119 static TimeDelta FromQPCValue(LONGLONG qpc_value); | 119 static TimeDelta FromQPCValue(LONGLONG qpc_value); |
| 120 #endif | 120 #endif |
| 121 | 121 |
| 122 // Returns the maximum time delta, which should be greater than any reasonable |
| 123 // time delta we might compare it to. Adding or subtracting the maximum time |
| 124 // delta to a time or another time delta has an undefined result. |
| 125 static constexpr TimeDelta Max(); |
| 126 |
| 122 // Converts an integer value representing TimeDelta to a class. This is used | 127 // Converts an integer value representing TimeDelta to a class. This is used |
| 123 // when deserializing a |TimeDelta| structure, using a value known to be | 128 // when deserializing a |TimeDelta| structure, using a value known to be |
| 124 // compatible. It is not provided as a constructor because the integer type | 129 // compatible. It is not provided as a constructor because the integer type |
| 125 // may be unclear from the perspective of a caller. | 130 // may be unclear from the perspective of a caller. |
| 126 static TimeDelta FromInternalValue(int64_t delta) { return TimeDelta(delta); } | 131 static TimeDelta FromInternalValue(int64_t delta) { return TimeDelta(delta); } |
| 127 | 132 |
| 128 // Returns the maximum time delta, which should be greater than any reasonable | |
| 129 // time delta we might compare it to. Adding or subtracting the maximum time | |
| 130 // delta to a time or another time delta has an undefined result. | |
| 131 static TimeDelta Max(); | |
| 132 | |
| 133 // Returns the internal numeric value of the TimeDelta object. Please don't | 133 // Returns the internal numeric value of the TimeDelta object. Please don't |
| 134 // use this and do arithmetic on it, as it is more error prone than using the | 134 // use this and do arithmetic on it, as it is more error prone than using the |
| 135 // provided operators. | 135 // provided operators. |
| 136 // For serializing, use FromInternalValue to reconstitute. | 136 // For serializing, use FromInternalValue to reconstitute. |
| 137 int64_t ToInternalValue() const { return delta_; } | 137 int64_t ToInternalValue() const { return delta_; } |
| 138 | 138 |
| 139 // Returns the magnitude (absolute value) of this TimeDelta. | 139 // Returns the magnitude (absolute value) of this TimeDelta. |
| 140 TimeDelta magnitude() const { | 140 TimeDelta magnitude() const { |
| 141 // Some toolchains provide an incomplete C++11 implementation and lack an | 141 // Some toolchains provide an incomplete C++11 implementation and lack an |
| 142 // int64_t overload for std::abs(). The following is a simple branchless | 142 // int64_t overload for std::abs(). The following is a simple branchless |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) { | 647 constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) { |
| 648 return FromDouble(ms * Time::kMicrosecondsPerMillisecond); | 648 return FromDouble(ms * Time::kMicrosecondsPerMillisecond); |
| 649 } | 649 } |
| 650 | 650 |
| 651 // static | 651 // static |
| 652 constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) { | 652 constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) { |
| 653 return TimeDelta(us); | 653 return TimeDelta(us); |
| 654 } | 654 } |
| 655 | 655 |
| 656 // static | 656 // static |
| 657 constexpr TimeDelta TimeDelta::Max() { |
| 658 return TimeDelta(std::numeric_limits<int64_t>::max()); |
| 659 } |
| 660 |
| 661 // static |
| 657 constexpr TimeDelta TimeDelta::FromDouble(double value) { | 662 constexpr TimeDelta TimeDelta::FromDouble(double value) { |
| 658 // TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out | 663 // TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out |
| 659 // the Min() behavior. | 664 // the Min() behavior. |
| 660 return value > std::numeric_limits<int64_t>::max() | 665 return value > std::numeric_limits<int64_t>::max() |
| 661 ? Max() | 666 ? Max() |
| 662 : value < -std::numeric_limits<int64_t>::max() | 667 : value < -std::numeric_limits<int64_t>::max() |
| 663 ? -Max() | 668 ? -Max() |
| 664 : TimeDelta(static_cast<int64_t>(value)); | 669 : TimeDelta(static_cast<int64_t>(value)); |
| 665 } | 670 } |
| 666 | 671 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 static void WaitUntilInitializedWin(); | 835 static void WaitUntilInitializedWin(); |
| 831 #endif | 836 #endif |
| 832 }; | 837 }; |
| 833 | 838 |
| 834 // For logging use only. | 839 // For logging use only. |
| 835 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 840 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
| 836 | 841 |
| 837 } // namespace base | 842 } // namespace base |
| 838 | 843 |
| 839 #endif // BASE_TIME_TIME_H_ | 844 #endif // BASE_TIME_TIME_H_ |
| OLD | NEW |