From 71d16f25ff9a52275ae5e673e6f817eb2cf390bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 26 Mar 2020 22:31:33 +0000 Subject: [PATCH] Don't use a static mtid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mud.c b/mud.c index 68918bc..6089426 100644 --- a/mud.c +++ b/mud.c @@ -161,6 +161,9 @@ struct mud { uint64_t window; uint64_t window_time; uint64_t base_time; +#if defined __APPLE__ + mach_timebase_info_data_t mtid; +#endif }; static int @@ -306,11 +309,8 @@ static uint64_t mud_now(struct mud *mud) { #if defined __APPLE__ - static mach_timebase_info_data_t mtid; - if (!mtid.denom) - mach_timebase_info(&mtid); return MUD_TIME_MASK(mud->base_time - + (mach_absolute_time() * mtid.numer / mtid.denom) + + (mach_absolute_time() * mud->mtid.numer / mud->mtid.denom) / 1000ULL); #elif defined CLOCK_MONOTONIC struct timespec tv; @@ -938,6 +938,10 @@ mud_create(struct sockaddr *addr) memcpy(&mud->addr, addr, addrlen); +#if defined __APPLE__ + mach_timebase_info(&mud->mtid); +#endif + uint64_t now = mud_now(mud); uint64_t base_time = mud_time();