Chromium Code Reviews| Index: base/time/time_mac.cc |
| diff --git a/base/time/time_mac.cc b/base/time/time_mac.cc |
| index 0ae3a30a3251419baead95006ed1d71843e8750c..9b3f0fe519d4921005caba74e164dcb5b5b465b4 100644 |
| --- a/base/time/time_mac.cc |
| +++ b/base/time/time_mac.cc |
| @@ -23,6 +23,11 @@ |
| #include "base/numerics/safe_conversions.h" |
| #include "build/build_config.h" |
| +#if defined(OS_IOS) |
| +#include <time.h> |
| +#include "base/ios/ios_util.h" |
| +#endif |
| + |
| namespace { |
| #if defined(OS_MACOSX) && !defined(OS_IOS) |
| @@ -52,8 +57,20 @@ int64_t MachAbsoluteTimeToTicks(uint64_t mach_absolute_time) { |
| } |
| #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| +// Returns monotonically growing number of ticks in milliseconds since some |
|
miu
2017/05/22 22:16:14
s/milliseconds/microseconds/
kapishnikov
2017/05/23 17:56:50
Done.
|
| +// unspecified starting point. |
| int64_t ComputeCurrentTicks() { |
| #if defined(OS_IOS) |
| + // iOS 10 supports clock_gettime(CLOCK_MONOTONIC, ...), which is |
| + // around 15 times faster than sysctl() call. Use it if possible; |
| + // otherwise, fall back to sysctl(). |
| + if (base::ios::IsRunningOnIOS10OrLater()) { |
| + struct timespec tp; |
| + if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) { |
|
miu
2017/05/22 22:16:14
Hmm...Curious that the POSIX compatibility layer w
kapishnikov
2017/05/23 17:56:50
I couldn't find the sources but my guess is that i
|
| + return tp.tv_sec * 1000000 + tp.tv_nsec / 1000; |
| + } |
| + } |
| + |
| // On iOS mach_absolute_time stops while the device is sleeping. Instead use |
| // now - KERN_BOOTTIME to get a time difference that is not impacted by clock |
| // changes. KERN_BOOTTIME will be updated by the system whenever the system |