| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 #ifndef V8_BASE_PLATFORM_TIME_H_ | 5 #ifndef V8_BASE_PLATFORM_TIME_H_ |
| 6 #define V8_BASE_PLATFORM_TIME_H_ | 6 #define V8_BASE_PLATFORM_TIME_H_ |
| 7 | 7 |
| 8 #include <ctime> | 8 #include <ctime> |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 class Time; | 25 class Time; |
| 26 class TimeTicks; | 26 class TimeTicks; |
| 27 | 27 |
| 28 // ----------------------------------------------------------------------------- | 28 // ----------------------------------------------------------------------------- |
| 29 // TimeDelta | 29 // TimeDelta |
| 30 // | 30 // |
| 31 // This class represents a duration of time, internally represented in | 31 // This class represents a duration of time, internally represented in |
| 32 // microseonds. | 32 // microseonds. |
| 33 | 33 |
| 34 class TimeDelta FINAL { | 34 class TimeDelta final { |
| 35 public: | 35 public: |
| 36 TimeDelta() : delta_(0) {} | 36 TimeDelta() : delta_(0) {} |
| 37 | 37 |
| 38 // Converts units of time to TimeDeltas. | 38 // Converts units of time to TimeDeltas. |
| 39 static TimeDelta FromDays(int days); | 39 static TimeDelta FromDays(int days); |
| 40 static TimeDelta FromHours(int hours); | 40 static TimeDelta FromHours(int hours); |
| 41 static TimeDelta FromMinutes(int minutes); | 41 static TimeDelta FromMinutes(int minutes); |
| 42 static TimeDelta FromSeconds(int64_t seconds); | 42 static TimeDelta FromSeconds(int64_t seconds); |
| 43 static TimeDelta FromMilliseconds(int64_t milliseconds); | 43 static TimeDelta FromMilliseconds(int64_t milliseconds); |
| 44 static TimeDelta FromMicroseconds(int64_t microseconds) { | 44 static TimeDelta FromMicroseconds(int64_t microseconds) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 int64_t delta_; | 152 int64_t delta_; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 | 155 |
| 156 // ----------------------------------------------------------------------------- | 156 // ----------------------------------------------------------------------------- |
| 157 // Time | 157 // Time |
| 158 // | 158 // |
| 159 // This class represents an absolute point in time, internally represented as | 159 // This class represents an absolute point in time, internally represented as |
| 160 // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970. | 160 // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970. |
| 161 | 161 |
| 162 class Time FINAL { | 162 class Time final { |
| 163 public: | 163 public: |
| 164 static const int64_t kMillisecondsPerSecond = 1000; | 164 static const int64_t kMillisecondsPerSecond = 1000; |
| 165 static const int64_t kMicrosecondsPerMillisecond = 1000; | 165 static const int64_t kMicrosecondsPerMillisecond = 1000; |
| 166 static const int64_t kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * | 166 static const int64_t kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * |
| 167 kMillisecondsPerSecond; | 167 kMillisecondsPerSecond; |
| 168 static const int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; | 168 static const int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; |
| 169 static const int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60; | 169 static const int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60; |
| 170 static const int64_t kMicrosecondsPerDay = kMicrosecondsPerHour * 24; | 170 static const int64_t kMicrosecondsPerDay = kMicrosecondsPerHour * 24; |
| 171 static const int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; | 171 static const int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; |
| 172 static const int64_t kNanosecondsPerMicrosecond = 1000; | 172 static const int64_t kNanosecondsPerMicrosecond = 1000; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // ----------------------------------------------------------------------------- | 291 // ----------------------------------------------------------------------------- |
| 292 // TimeTicks | 292 // TimeTicks |
| 293 // | 293 // |
| 294 // This class represents an abstract time that is most of the time incrementing | 294 // This class represents an abstract time that is most of the time incrementing |
| 295 // for use in measuring time durations. It is internally represented in | 295 // for use in measuring time durations. It is internally represented in |
| 296 // microseconds. It can not be converted to a human-readable time, but is | 296 // microseconds. It can not be converted to a human-readable time, but is |
| 297 // guaranteed not to decrease (if the user changes the computer clock, | 297 // guaranteed not to decrease (if the user changes the computer clock, |
| 298 // Time::Now() may actually decrease or jump). But note that TimeTicks may | 298 // Time::Now() may actually decrease or jump). But note that TimeTicks may |
| 299 // "stand still", for example if the computer suspended. | 299 // "stand still", for example if the computer suspended. |
| 300 | 300 |
| 301 class TimeTicks FINAL { | 301 class TimeTicks final { |
| 302 public: | 302 public: |
| 303 TimeTicks() : ticks_(0) {} | 303 TimeTicks() : ticks_(0) {} |
| 304 | 304 |
| 305 // Platform-dependent tick count representing "right now." | 305 // Platform-dependent tick count representing "right now." |
| 306 // The resolution of this clock is ~1-15ms. Resolution varies depending | 306 // The resolution of this clock is ~1-15ms. Resolution varies depending |
| 307 // on hardware/operating system configuration. | 307 // on hardware/operating system configuration. |
| 308 // This method never returns a null TimeTicks. | 308 // This method never returns a null TimeTicks. |
| 309 static TimeTicks Now(); | 309 static TimeTicks Now(); |
| 310 | 310 |
| 311 // Returns a platform-dependent high-resolution tick count. Implementation | 311 // Returns a platform-dependent high-resolution tick count. Implementation |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 int64_t ticks_; | 394 int64_t ticks_; |
| 395 }; | 395 }; |
| 396 | 396 |
| 397 inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) { | 397 inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) { |
| 398 return ticks + delta; | 398 return ticks + delta; |
| 399 } | 399 } |
| 400 | 400 |
| 401 } } // namespace v8::base | 401 } } // namespace v8::base |
| 402 | 402 |
| 403 #endif // V8_BASE_PLATFORM_TIME_H_ | 403 #endif // V8_BASE_PLATFORM_TIME_H_ |
| OLD | NEW |