diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-12-08 09:24:02 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-12-08 09:24:02 -0500 |
commit | 021fdd39e4ebbe8ddee9b10823af76fbb11e7878 (patch) | |
tree | 993dd4ef79f5d5deb3dd48777ea7b50f18843a6e /src/common/compat_time.c | |
parent | afceb431ed3a1c4daf303e5245a05f800d596fa6 (diff) | |
download | tor-021fdd39e4ebbe8ddee9b10823af76fbb11e7878.tar.gz tor-021fdd39e4ebbe8ddee9b10823af76fbb11e7878.zip |
Use mach_approximate_time() for coarse time where available.
This lets us have a coarse-time implementation with reasonable
performance characteristics on OSX and iOS.
Implements 24427.
Diffstat (limited to 'src/common/compat_time.c')
-rw-r--r-- | src/common/compat_time.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/compat_time.c b/src/common/compat_time.c index 204b8d7d15..c0cd73c74d 100644 --- a/src/common/compat_time.c +++ b/src/common/compat_time.c @@ -314,6 +314,21 @@ monotime_get(monotime_t *out) out->abstime_ = mach_absolute_time(); } +#if defined(HAVE_MACH_APPROXIMATE_TIME) +void +monotime_coarse_get(monotime_coarse_t *out) +{ +#ifdef TOR_UNIT_TESTS + if (monotime_mocking_enabled) { + out->abstime_ = (mock_time_nsec_coarse * mach_time_info.denom) + / mach_time_info.numer; + return; + } +#endif /* defined(TOR_UNIT_TESTS) */ + out->abstime_ = mach_approximate_time(); +} +#endif + /** * Return the number of nanoseconds between <b>start</b> and <b>end</b>. */ |