OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 time, internally represented as | 5 // Time represents an absolute point in time, internally represented as |
6 // microseconds (s/1,000,000) since a platform-dependent epoch. Each | 6 // microseconds (s/1,000,000) since a platform-dependent epoch. Each |
7 // platform's epoch, along with other system-dependent clock interface | 7 // platform's epoch, along with other system-dependent clock interface |
8 // routines, is defined in time_PLATFORM.cc. | 8 // routines, is defined in time_PLATFORM.cc. |
9 // | 9 // |
10 // TimeDelta represents a duration of time, internally represented in | 10 // TimeDelta represents a duration of time, internally represented in |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // When disabling the high resolution timer, this function will not cause | 276 // When disabling the high resolution timer, this function will not cause |
277 // the high resolution timer to be deactivated, but will prevent future | 277 // the high resolution timer to be deactivated, but will prevent future |
278 // activations. | 278 // activations. |
279 // Must be called from the main thread. | 279 // Must be called from the main thread. |
280 // For more details see comments in time_win.cc. | 280 // For more details see comments in time_win.cc. |
281 static void EnableHighResolutionTimer(bool enable); | 281 static void EnableHighResolutionTimer(bool enable); |
282 | 282 |
283 // Activates or deactivates the high resolution timer based on the |activate| | 283 // Activates or deactivates the high resolution timer based on the |activate| |
284 // flag. If the HighResolutionTimer is not Enabled (see | 284 // flag. If the HighResolutionTimer is not Enabled (see |
285 // EnableHighResolutionTimer), this function will return false. Otherwise | 285 // EnableHighResolutionTimer), this function will return false. Otherwise |
286 // returns true. Each successful activate call must be paired with a | 286 // returns true. |
287 // subsequent deactivate call. | |
288 // All callers to activate the high resolution timer must eventually call | 287 // All callers to activate the high resolution timer must eventually call |
289 // this function to deactivate the high resolution timer. | 288 // this function to deactivate the high resolution timer. |
290 static bool ActivateHighResolutionTimer(bool activate); | 289 static bool ActivateHighResolutionTimer(bool activate); |
291 | |
292 // Returns true if the high resolution timer is both enabled and activated. | |
293 // This is provided for testing only, and is not tracked in a thread-safe | |
294 // way. | |
295 static bool IsHighResolutionTimerInUse(); | |
296 #endif | 290 #endif |
297 | 291 |
298 // Converts an exploded structure representing either the local time or UTC | 292 // Converts an exploded structure representing either the local time or UTC |
299 // into a Time class. | 293 // into a Time class. |
300 static Time FromUTCExploded(const Exploded& exploded) { | 294 static Time FromUTCExploded(const Exploded& exploded) { |
301 return FromExploded(false, exploded); | 295 return FromExploded(false, exploded); |
302 } | 296 } |
303 static Time FromLocalExploded(const Exploded& exploded) { | 297 static Time FromLocalExploded(const Exploded& exploded) { |
304 return FromExploded(true, exploded); | 298 return FromExploded(true, exploded); |
305 } | 299 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 398 |
405 // The representation of Jan 1, 1970 UTC in microseconds since the | 399 // The representation of Jan 1, 1970 UTC in microseconds since the |
406 // platform-dependent epoch. | 400 // platform-dependent epoch. |
407 static const int64 kTimeTToMicrosecondsOffset; | 401 static const int64 kTimeTToMicrosecondsOffset; |
408 | 402 |
409 #if defined(OS_WIN) | 403 #if defined(OS_WIN) |
410 // Indicates whether fast timers are usable right now. For instance, | 404 // Indicates whether fast timers are usable right now. For instance, |
411 // when using battery power, we might elect to prevent high speed timers | 405 // when using battery power, we might elect to prevent high speed timers |
412 // which would draw more power. | 406 // which would draw more power. |
413 static bool high_resolution_timer_enabled_; | 407 static bool high_resolution_timer_enabled_; |
414 // Count of activations on the high resolution timer. Only use in tests | |
415 // which are single threaded. | |
416 static int high_resolution_timer_activated_; | |
417 #endif | 408 #endif |
418 | 409 |
419 // Time in microseconds in UTC. | 410 // Time in microseconds in UTC. |
420 int64 us_; | 411 int64 us_; |
421 }; | 412 }; |
422 | 413 |
423 inline Time TimeDelta::operator+(Time t) const { | 414 inline Time TimeDelta::operator+(Time t) const { |
424 return Time(t.us_ + delta_); | 415 return Time(t.us_ + delta_); |
425 } | 416 } |
426 | 417 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 #endif | 550 #endif |
560 }; | 551 }; |
561 | 552 |
562 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 553 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
563 return TimeTicks(t.ticks_ + delta_); | 554 return TimeTicks(t.ticks_ + delta_); |
564 } | 555 } |
565 | 556 |
566 } // namespace base | 557 } // namespace base |
567 | 558 |
568 #endif // BASE_TIME_H_ | 559 #endif // BASE_TIME_H_ |
OLD | NEW |