mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
Expose a function that computes stamp units from msec.
(It turns out we can't just expose STAMP_TICKS_PER_SECOND, since Apple doesn't have that.)
This commit is contained in:
parent
16f08de0fd
commit
d8ef9a2d1e
@ -830,11 +830,24 @@ monotime_coarse_stamp_units_to_approx_msec(uint64_t units)
|
|||||||
return (abstime_diff * mach_time_info.numer) /
|
return (abstime_diff * mach_time_info.numer) /
|
||||||
(mach_time_info.denom * ONE_MILLION);
|
(mach_time_info.denom * ONE_MILLION);
|
||||||
}
|
}
|
||||||
|
uint64_t
|
||||||
|
monotime_msec_to_approx_coarse_stamp_units(uint64_t msec)
|
||||||
|
{
|
||||||
|
uint64_t abstime_val =
|
||||||
|
(((uint64_t)msec) * ONE_MILLION * mach_time_info.denom) /
|
||||||
|
mach_time_info.numer;
|
||||||
|
return abstime_val >> monotime_shift;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
uint64_t
|
uint64_t
|
||||||
monotime_coarse_stamp_units_to_approx_msec(uint64_t units)
|
monotime_coarse_stamp_units_to_approx_msec(uint64_t units)
|
||||||
{
|
{
|
||||||
return (units * 1000) / STAMP_TICKS_PER_SECOND;
|
return (units * 1000) / STAMP_TICKS_PER_SECOND;
|
||||||
}
|
}
|
||||||
|
uint64_t
|
||||||
|
monotime_msec_to_approx_coarse_stamp_units(uint64_t msec)
|
||||||
|
{
|
||||||
|
return (msec * STAMP_TICKS_PER_SECOND) / 1000;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -150,6 +150,7 @@ uint32_t monotime_coarse_to_stamp(const monotime_coarse_t *t);
|
|||||||
* into an approximate number of milliseconds.
|
* into an approximate number of milliseconds.
|
||||||
*/
|
*/
|
||||||
uint64_t monotime_coarse_stamp_units_to_approx_msec(uint64_t units);
|
uint64_t monotime_coarse_stamp_units_to_approx_msec(uint64_t units);
|
||||||
|
uint64_t monotime_msec_to_approx_coarse_stamp_units(uint64_t msec);
|
||||||
uint32_t monotime_coarse_get_stamp(void);
|
uint32_t monotime_coarse_get_stamp(void);
|
||||||
|
|
||||||
#if defined(MONOTIME_COARSE_TYPE_IS_DIFFERENT)
|
#if defined(MONOTIME_COARSE_TYPE_IS_DIFFERENT)
|
||||||
|
@ -5907,6 +5907,13 @@ test_util_monotonic_time(void *arg)
|
|||||||
tt_u64_op(coarse_stamp_diff, OP_GE, 120);
|
tt_u64_op(coarse_stamp_diff, OP_GE, 120);
|
||||||
tt_u64_op(coarse_stamp_diff, OP_LE, 1200);
|
tt_u64_op(coarse_stamp_diff, OP_LE, 1200);
|
||||||
|
|
||||||
|
{
|
||||||
|
uint64_t units = monotime_msec_to_approx_coarse_stamp_units(5000);
|
||||||
|
uint64_t ms = monotime_coarse_stamp_units_to_approx_msec(units);
|
||||||
|
tt_int_op(ms, OP_GE, 4950);
|
||||||
|
tt_int_op(ms, OP_LT, 5050);
|
||||||
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user