mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
arch/sim: fix host_settimer clock mismatch on macOS
dispatch_walltime() expects a delta in nanoseconds from now, but the previous code subtracted CLOCK_REALTIME from a CLOCK_MONOTONIC absolute timestamp, which have different epochs and produce a meaningless result. Fix by subtracting the current CLOCK_MONOTONIC absolute time to get the correct remaining duration. Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
@@ -193,7 +193,12 @@ int host_settimer(uint64_t nsec)
|
||||
#ifdef __APPLE__
|
||||
dispatch_time_t start;
|
||||
|
||||
start = dispatch_walltime(NULL, nsec - host_gettime(true));
|
||||
struct timespec now;
|
||||
uint64_t now_ns;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
now_ns = 1000000000ull * now.tv_sec + now.tv_nsec;
|
||||
start = dispatch_walltime(NULL, nsec - now_ns);
|
||||
dispatch_source_set_timer(g_timer, start, DISPATCH_TIME_FOREVER, 1000);
|
||||
return 0;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user