Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: base/time.h

Issue 2822035: Change chrome from statically enabling high resolution timers on windows... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/test/test_suite.h ('k') | base/time_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 double ToDoubleT() const; 247 double ToDoubleT() const;
248 248
249 #if defined(OS_POSIX) 249 #if defined(OS_POSIX)
250 struct timeval ToTimeVal() const; 250 struct timeval ToTimeVal() const;
251 #endif 251 #endif
252 252
253 #if defined(OS_WIN) 253 #if defined(OS_WIN)
254 static Time FromFileTime(FILETIME ft); 254 static Time FromFileTime(FILETIME ft);
255 FILETIME ToFileTime() const; 255 FILETIME ToFileTime() const;
256 256
257 // Enable or disable Windows high resolution timer. For more details 257 // The minimum time of a low resolution timer. This is basically a windows
258 // see comments in time_win.cc. Returns true on success. 258 // constant of ~15.6ms. While it does vary on some older OS versions, we'll
259 static bool UseHighResolutionTimer(bool use); 259 // treat it as static across all windows versions.
260 static const int kMinLowResolutionThresholdMs = 16;
261
262 // Enable or disable Windows high resolution timer. If the high resolution
263 // timer is not enabled, calls to ActivateHighResolutionTimer will fail.
264 // When disabling the high resolution timer, this function will not cause
265 // the high resolution timer to be deactivated, but will prevent future
266 // activations.
267 // Must be called from the main thread.
268 // For more details see comments in time_win.cc.
269 static void EnableHighResolutionTimer(bool enable);
270
271 // Activates or deactivates the high resolution timer based on the |activate|
272 // flag. If the HighResolutionTimer is not Enabled (see
273 // EnableHighResolutionTimer), this function will return false. Otherwise
274 // returns true.
275 // All callers to activate the high resolution timer must eventually call
276 // this function to deactivate the high resolution timer.
277 static bool ActivateHighResolutionTimer(bool activate);
260 #endif 278 #endif
261 279
262 // Converts an exploded structure representing either the local time or UTC 280 // Converts an exploded structure representing either the local time or UTC
263 // into a Time class. 281 // into a Time class.
264 static Time FromUTCExploded(const Exploded& exploded) { 282 static Time FromUTCExploded(const Exploded& exploded) {
265 return FromExploded(false, exploded); 283 return FromExploded(false, exploded);
266 } 284 }
267 static Time FromLocalExploded(const Exploded& exploded) { 285 static Time FromLocalExploded(const Exploded& exploded) {
268 return FromExploded(true, exploded); 286 return FromExploded(true, exploded);
269 } 287 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // |is_local = true| or UTC |is_local = false|. 381 // |is_local = true| or UTC |is_local = false|.
364 static Time FromExploded(bool is_local, const Exploded& exploded); 382 static Time FromExploded(bool is_local, const Exploded& exploded);
365 383
366 explicit Time(int64 us) : us_(us) { 384 explicit Time(int64 us) : us_(us) {
367 } 385 }
368 386
369 // The representation of Jan 1, 1970 UTC in microseconds since the 387 // The representation of Jan 1, 1970 UTC in microseconds since the
370 // platform-dependent epoch. 388 // platform-dependent epoch.
371 static const int64 kTimeTToMicrosecondsOffset; 389 static const int64 kTimeTToMicrosecondsOffset;
372 390
391 #if defined(OS_WIN)
392 // Indicates whether fast timers are usable right now. For instance,
393 // when using battery power, we might elect to prevent high speed timers
394 // which would draw more power.
395 static bool high_resolution_timer_enabled_;
396 #endif
397
373 // Time in microseconds in UTC. 398 // Time in microseconds in UTC.
374 int64 us_; 399 int64 us_;
375 }; 400 };
376 401
377 inline Time TimeDelta::operator+(Time t) const { 402 inline Time TimeDelta::operator+(Time t) const {
378 return Time(t.us_ + delta_); 403 return Time(t.us_ + delta_);
379 } 404 }
380 405
381 // Inline the TimeDelta factory methods, for fast TimeDelta construction. 406 // Inline the TimeDelta factory methods, for fast TimeDelta construction.
382 407
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 #endif 529 #endif
505 }; 530 };
506 531
507 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { 532 inline TimeTicks TimeDelta::operator+(TimeTicks t) const {
508 return TimeTicks(t.ticks_ + delta_); 533 return TimeTicks(t.ticks_ + delta_);
509 } 534 }
510 535
511 } // namespace base 536 } // namespace base
512 537
513 #endif // BASE_TIME_H_ 538 #endif // BASE_TIME_H_
OLDNEW
« no previous file with comments | « base/test/test_suite.h ('k') | base/time_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698