summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 18:50:31 +0000
committermmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 18:50:31 +0000
commit07a0e3f008d9e801b203d44c21de91dad825d468 (patch)
tree1df72f420718c6df3c2bb7401329f0a84073452c /base
parent8f19cdc936536100087ee8c78f6a3bf1082131db (diff)
downloadchromium_src-07a0e3f008d9e801b203d44c21de91dad825d468.zip
chromium_src-07a0e3f008d9e801b203d44c21de91dad825d468.tar.gz
chromium_src-07a0e3f008d9e801b203d44c21de91dad825d468.tar.bz2
Get rid of an unneded static variable in the Mac TimeTicks::Now
Review URL: http://codereview.chromium.org/1849 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/time_posix.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/base/time_posix.cc b/base/time_posix.cc
index c093a11..793687e 100644
--- a/base/time_posix.cc
+++ b/base/time_posix.cc
@@ -92,12 +92,16 @@ TimeTicks TimeTicks::Now() {
#if defined(OS_MACOSX)
- static bool has_timebase_info = false;
- static mach_timebase_info_data_t timebase_info = {1, 1};
- if (!has_timebase_info) {
- has_timebase_info = mach_timebase_info(&timebase_info) == KERN_SUCCESS;
+ static mach_timebase_info_data_t timebase_info;
+ if (timebase_info.denom == 0) {
+ // Zero-initialization of statics guarantees that denom will be 0 before
+ // calling mach_timebase_info. mach_timebase_info will never set denom to
+ // 0 as that would be invalid, so the zero-check can be used to determine
+ // whether mach_timebase_info has already been called. This is
+ // recommended by Apple's QA1398.
+ kern_return_t kr = mach_timebase_info(&timebase_info);
+ DCHECK(kr == KERN_SUCCESS);
}
- DCHECK(has_timebase_info) << "Could not determine system tick rate";
// mach_absolute_time is it when it comes to ticks on the Mac. Other calls
// with less precision (such as TickCount) just call through to
@@ -114,6 +118,7 @@ TimeTicks TimeTicks::Now() {
#elif defined(OS_POSIX) && \
defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
+
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed.";
@@ -135,4 +140,3 @@ TimeTicks TimeTicks::Now() {
TimeTicks TimeTicks::UnreliableHighResNow() {
return Now();
}
-