| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/time.h" | 5 #include "base/time.h" |
| 6 | 6 |
| 7 #ifdef OS_MACOSX | 7 #ifdef OS_MACOSX |
| 8 #include <mach/mach_time.h> | 8 #include <mach/mach_time.h> |
| 9 #endif | 9 #endif |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // timebase_info converts absolute time tick units into nanoseconds. Convert | 150 // timebase_info converts absolute time tick units into nanoseconds. Convert |
| 151 // to microseconds up front to stave off overflows. | 151 // to microseconds up front to stave off overflows. |
| 152 absolute_micro = mach_absolute_time() / Time::kNanosecondsPerMicrosecond * | 152 absolute_micro = mach_absolute_time() / Time::kNanosecondsPerMicrosecond * |
| 153 timebase_info.numer / timebase_info.denom; | 153 timebase_info.numer / timebase_info.denom; |
| 154 | 154 |
| 155 // Don't bother with the rollover handling that the Windows version does. | 155 // Don't bother with the rollover handling that the Windows version does. |
| 156 // With numer and denom = 1 (the expected case), the 64-bit absolute time | 156 // With numer and denom = 1 (the expected case), the 64-bit absolute time |
| 157 // reported in nanoseconds is enough to last nearly 585 years. | 157 // reported in nanoseconds is enough to last nearly 585 years. |
| 158 | 158 |
| 159 #elif defined(OS_POSIX) && \ | 159 #elif defined(OS_POSIX) && \ |
| 160 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 | 160 ((defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ |
| 161 defined(OS_OPENBSD)) |
| 161 | 162 |
| 162 struct timespec ts; | 163 struct timespec ts; |
| 163 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 164 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
| 164 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; | 165 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; |
| 165 return TimeTicks(); | 166 return TimeTicks(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 absolute_micro = | 169 absolute_micro = |
| 169 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 170 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 170 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 171 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 171 | 172 |
| 172 #else // _POSIX_MONOTONIC_CLOCK | 173 #else // _POSIX_MONOTONIC_CLOCK |
| 173 #error No usable tick clock function on this platform. | 174 #error No usable tick clock function on this platform. |
| 174 #endif // _POSIX_MONOTONIC_CLOCK | 175 #endif // _POSIX_MONOTONIC_CLOCK |
| 175 | 176 |
| 176 return TimeTicks(absolute_micro); | 177 return TimeTicks(absolute_micro); |
| 177 } | 178 } |
| 178 | 179 |
| 179 // static | 180 // static |
| 180 TimeTicks TimeTicks::HighResNow() { | 181 TimeTicks TimeTicks::HighResNow() { |
| 181 return Now(); | 182 return Now(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace base | 185 } // namespace base |
| OLD | NEW |