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

Unified Diff: base/time/time_mac.cc

Issue 2894173002: Use faster clock_gettime() instead of sysctl() to get current ticks on iOS10 (Closed)
Patch Set: Small fix Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/quic/platform/impl/quic_chromium_clock.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_mac.cc
diff --git a/base/time/time_mac.cc b/base/time/time_mac.cc
index 0ae3a30a3251419baead95006ed1d71843e8750c..91fd17b5dfc21b003b45010dcdc463e5f75534a2 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 microseconds since some
+// 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) {
+ 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
« no previous file with comments | « no previous file | net/quic/platform/impl/quic_chromium_clock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698