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_PLATFORM_TIME_H_ | 5 #ifndef V8_PLATFORM_TIME_H_ |
6 #define V8_PLATFORM_TIME_H_ | 6 #define V8_PLATFORM_TIME_H_ |
7 | 7 |
8 #include <time.h> | 8 #include <time.h> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "src/allocation.h" | 11 #include "src/base/macros.h" |
12 | 12 |
13 // Forward declarations. | 13 // Forward declarations. |
14 extern "C" { | 14 extern "C" { |
15 struct _FILETIME; | 15 struct _FILETIME; |
16 struct mach_timespec; | 16 struct mach_timespec; |
17 struct timespec; | 17 struct timespec; |
18 struct timeval; | 18 struct timeval; |
19 } | 19 } |
20 | 20 |
21 namespace v8 { | 21 namespace v8 { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 class Time; | 24 class Time; |
25 class TimeTicks; | 25 class TimeTicks; |
26 | 26 |
27 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
28 // TimeDelta | 28 // TimeDelta |
29 // | 29 // |
30 // This class represents a duration of time, internally represented in | 30 // This class represents a duration of time, internally represented in |
31 // microseonds. | 31 // microseonds. |
32 | 32 |
33 class TimeDelta V8_FINAL BASE_EMBEDDED { | 33 class TimeDelta V8_FINAL { |
34 public: | 34 public: |
35 TimeDelta() : delta_(0) {} | 35 TimeDelta() : delta_(0) {} |
36 | 36 |
37 // Converts units of time to TimeDeltas. | 37 // Converts units of time to TimeDeltas. |
38 static TimeDelta FromDays(int days); | 38 static TimeDelta FromDays(int days); |
39 static TimeDelta FromHours(int hours); | 39 static TimeDelta FromHours(int hours); |
40 static TimeDelta FromMinutes(int minutes); | 40 static TimeDelta FromMinutes(int minutes); |
41 static TimeDelta FromSeconds(int64_t seconds); | 41 static TimeDelta FromSeconds(int64_t seconds); |
42 static TimeDelta FromMilliseconds(int64_t milliseconds); | 42 static TimeDelta FromMilliseconds(int64_t milliseconds); |
43 static TimeDelta FromMicroseconds(int64_t microseconds) { | 43 static TimeDelta FromMicroseconds(int64_t microseconds) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 int64_t delta_; | 151 int64_t delta_; |
152 }; | 152 }; |
153 | 153 |
154 | 154 |
155 // ----------------------------------------------------------------------------- | 155 // ----------------------------------------------------------------------------- |
156 // Time | 156 // Time |
157 // | 157 // |
158 // This class represents an absolute point in time, internally represented as | 158 // This class represents an absolute point in time, internally represented as |
159 // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970. | 159 // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970. |
160 | 160 |
161 class Time V8_FINAL BASE_EMBEDDED { | 161 class Time V8_FINAL { |
162 public: | 162 public: |
163 static const int64_t kMillisecondsPerSecond = 1000; | 163 static const int64_t kMillisecondsPerSecond = 1000; |
164 static const int64_t kMicrosecondsPerMillisecond = 1000; | 164 static const int64_t kMicrosecondsPerMillisecond = 1000; |
165 static const int64_t kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * | 165 static const int64_t kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * |
166 kMillisecondsPerSecond; | 166 kMillisecondsPerSecond; |
167 static const int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; | 167 static const int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; |
168 static const int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60; | 168 static const int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60; |
169 static const int64_t kMicrosecondsPerDay = kMicrosecondsPerHour * 24; | 169 static const int64_t kMicrosecondsPerDay = kMicrosecondsPerHour * 24; |
170 static const int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; | 170 static const int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; |
171 static const int64_t kNanosecondsPerMicrosecond = 1000; | 171 static const int64_t kNanosecondsPerMicrosecond = 1000; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // ----------------------------------------------------------------------------- | 288 // ----------------------------------------------------------------------------- |
289 // TimeTicks | 289 // TimeTicks |
290 // | 290 // |
291 // This class represents an abstract time that is most of the time incrementing | 291 // This class represents an abstract time that is most of the time incrementing |
292 // for use in measuring time durations. It is internally represented in | 292 // for use in measuring time durations. It is internally represented in |
293 // microseconds. It can not be converted to a human-readable time, but is | 293 // microseconds. It can not be converted to a human-readable time, but is |
294 // guaranteed not to decrease (if the user changes the computer clock, | 294 // guaranteed not to decrease (if the user changes the computer clock, |
295 // Time::Now() may actually decrease or jump). But note that TimeTicks may | 295 // Time::Now() may actually decrease or jump). But note that TimeTicks may |
296 // "stand still", for example if the computer suspended. | 296 // "stand still", for example if the computer suspended. |
297 | 297 |
298 class TimeTicks V8_FINAL BASE_EMBEDDED { | 298 class TimeTicks V8_FINAL { |
299 public: | 299 public: |
300 TimeTicks() : ticks_(0) {} | 300 TimeTicks() : ticks_(0) {} |
301 | 301 |
302 // Platform-dependent tick count representing "right now." | 302 // Platform-dependent tick count representing "right now." |
303 // The resolution of this clock is ~1-15ms. Resolution varies depending | 303 // The resolution of this clock is ~1-15ms. Resolution varies depending |
304 // on hardware/operating system configuration. | 304 // on hardware/operating system configuration. |
305 // This method never returns a null TimeTicks. | 305 // This method never returns a null TimeTicks. |
306 static TimeTicks Now(); | 306 static TimeTicks Now(); |
307 | 307 |
308 // Returns a platform-dependent high-resolution tick count. Implementation | 308 // Returns a platform-dependent high-resolution tick count. Implementation |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 int64_t ticks_; | 384 int64_t ticks_; |
385 }; | 385 }; |
386 | 386 |
387 inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) { | 387 inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) { |
388 return ticks + delta; | 388 return ticks + delta; |
389 } | 389 } |
390 | 390 |
391 } } // namespace v8::internal | 391 } } // namespace v8::internal |
392 | 392 |
393 #endif // V8_PLATFORM_TIME_H_ | 393 #endif // V8_PLATFORM_TIME_H_ |
OLD | NEW |