Clock: make monotonic_ms monotonic, so a clock jump can't freeze the session
CI / test (push) Failing after 52s
CI / test (push) Failing after 52s
It read the wall clock. When NTP moved a phone from 1970 to now, the frame loop's elapsed time overflowed and it slept for days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f51ce088ad
commit
4fd2641c80
4 files changed
+30
-3
No files matched your search
@@ -383,6 +383,15 @@ int32_t mp_getpid(void) {
|
||||
return (int32_t)getpid();
|
||||
}
|
||||
|
||||
/* Not the wall clock: that jumps (a phone boots in 1970 until NTP answers), and the frame loop
|
||||
* sleeps for the difference between two of these. */
|
||||
MOONBIT_FFI_EXPORT
|
||||
uint64_t mp_monotonic_ms(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
/* Local wall-clock field: 0 year, 1 month(1-12), 2 day, 3 hour, 4 minute, 5 second, 6 weekday(0=Sun). */
|
||||
MOONBIT_FFI_EXPORT
|
||||
int32_t mp_wall_time_field(int32_t which) {
|
||||
|
||||
Reference in new issue
Block a user