aboutsummaryrefslogtreecommitdiffstats
path: root/surfaces/screen.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-29 18:12:23 +0100
committereunhhu <[email protected]>2026-09-29 18:12:23 +0100
commitc919b5f81ad6cad55935fa7a22bfda9539dd584f (patch)
tree35a59078aad71e90b5d9f1f23f9f80355ed9325b /surfaces/screen.c
parent434e8a9930d954494a462690739ea4ead21ff4e8 (diff)
downloadvega-c919b5f81ad6cad55935fa7a22bfda9539dd584f.tar.gz
vega-c919b5f81ad6cad55935fa7a22bfda9539dd584f.zip
Wait for timers on the monotonic clock; events still see the wall clock
The terminal, the pixel surfaces and the web page reckoned when a timer was due on the wall clock: set back, a timer waited until the clock came again to the tick it had waited for (Pure's review 004). vega_clock is the monotonic clock; timers are due on it, and a tick sets the time its event sees from the wall clock (vega_now), as before. check.py's clock_set_back runs a timer of 20 ms in the terminal with the wall clock set back an hour 0.2 s in (Pure's build/clock-back.so, an LD_PRELOAD of clock_gettime): 40 ticks in 0.8 s, where Vega before this stops at 9. make check passes it --clock-back.
Diffstat (limited to 'surfaces/screen.c')
-rw-r--r--surfaces/screen.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/surfaces/screen.c b/surfaces/screen.c
index fdecaf4..f079bd5 100644
--- a/surfaces/screen.c
+++ b/surfaces/screen.c
@@ -11,23 +11,29 @@ double vega_now(void) {
return floor((double)t.tv_sec * 1000 + (double)t.tv_nsec / 1e6);
}
-void vega_timers_start(VegaTimers *timers, const PureModule *m, double now) {
+double vega_clock(void) {
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return floor((double)t.tv_sec * 1000 + (double)t.tv_nsec / 1e6);
+}
+
+void vega_timers_start(VegaTimers *timers, const PureModule *m, double clock) {
for (uint32_t i = 0; i < m->inputs; ++i)
- timers->next[i] = m->input[i].kind == PURE_KIND_TIMER ? now + m->input[i].period : 0;
+ timers->next[i] = m->input[i].kind == PURE_KIND_TIMER ? clock + m->input[i].period : 0;
}
-long vega_timers_run(VegaTimers *timers, PureApp *app, double now, bool *ticked) {
+long vega_timers_run(VegaTimers *timers, PureApp *app, double clock, bool *ticked) {
const PureModule *m = app->module;
double soonest = -1;
for (uint32_t i = 0; i < m->inputs; ++i) {
if (m->input[i].kind != PURE_KIND_TIMER) continue;
- if (timers->next[i] <= now) {
- app->now = now;
+ if (timers->next[i] <= clock) {
+ app->now = vega_now();
pure_app_tick(app, i); /* a failed tick changes nothing, as any failed event */
*ticked = true;
- timers->next[i] = now + m->input[i].period;
+ timers->next[i] = clock + m->input[i].period;
}
- if (soonest < 0 || timers->next[i] - now < soonest) soonest = timers->next[i] - now;
+ if (soonest < 0 || timers->next[i] - clock < soonest) soonest = timers->next[i] - clock;
}
return soonest < 0 ? -1 : (long)ceil(soonest);
}