aboutsummaryrefslogtreecommitdiff
path: root/src/lib/time/compat_time.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-10-14 09:12:23 -0400
committerDavid Goulet <dgoulet@torproject.org>2022-10-14 09:12:23 -0400
commit432b5797b9fc9dfae6a26848234e55e092ce7188 (patch)
tree04e6cfab0178ac88b526a4a2ee133d63e426929a /src/lib/time/compat_time.c
parent7c3c340caa167d476e368ab6e30a4174ed0bc233 (diff)
parente531d4d1b9753e80b56a28805b01c014a1fe5d51 (diff)
downloadtor-432b5797b9fc9dfae6a26848234e55e092ce7188.tar.gz
tor-432b5797b9fc9dfae6a26848234e55e092ce7188.zip
Merge branch 'maint-0.4.5' into release-0.4.5
Diffstat (limited to 'src/lib/time/compat_time.c')
-rw-r--r--src/lib/time/compat_time.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lib/time/compat_time.c b/src/lib/time/compat_time.c
index 6bbad4f98a..9a5ce062d7 100644
--- a/src/lib/time/compat_time.c
+++ b/src/lib/time/compat_time.c
@@ -253,11 +253,14 @@ monotime_init_internal(void)
tor_assert(mach_time_info.denom != 0);
{
- // approximate only.
- uint64_t ns_per_tick = mach_time_info.numer / mach_time_info.denom;
- uint64_t ms_per_tick = ns_per_tick * ONE_MILLION;
+ // We want to compute this, approximately:
+ // uint64_t ns_per_tick = mach_time_info.numer / mach_time_info.denom;
+ // uint64_t ticks_per_ms = ONE_MILLION / ns_per_tick;
+ // This calculation multiplies first, though, to improve accuracy.
+ uint64_t ticks_per_ms = (ONE_MILLION * mach_time_info.denom)
+ / mach_time_info.numer;
// requires that tor_log2(0) == 0.
- monotime_shift = tor_log2(ms_per_tick);
+ monotime_shift = tor_log2(ticks_per_ms);
}
{
// For converting ticks to milliseconds in a 32-bit-friendly way, we