From 591e145ed1d0e75b8f0b794d2781293e178d1e9f Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 12:04:09 -0800 Subject: [PATCH 14/24] SyncTERM: doterm sleeps instead of spinning while output is paced Pace emulated-speed output on a schedule, not from the last byte: bytes that came due while the loop slept go out as one burst, so the loop can sleep between bursts. A gap over 50 ms restarts the schedule. And do not self-wake while the speed gate or a suspend is what holds the backlog: that wake returned at once and spun a core until the backlog drained. --- src/syncterm/term.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/syncterm/term.c b/src/syncterm/term.c index 4a36cc04..1a9f034a 100644 --- a/src/syncterm/term.c +++ b/src/syncterm/term.c @@ -5491,8 +5491,17 @@ doterm(struct bbslist *bbs) break; default: if (speed) { + /* Pace on a schedule, not from the last + * byte: bytes that came due while the loop + * slept go out as one burst, so it can + * sleep between bursts instead of spinning + * a byte at a time. A gap longer than + * 50 ms restarts the schedule rather than + * banking a burst. */ lastchar = xp_timer(); - nextchar = lastchar + 1 / (long double)(speed / 10); + if (nextchar < lastchar - 0.05L) + nextchar = lastchar; + nextchar += 1 / (long double)(speed / 10); } if (check_speedwatch(&speedwatch, inch)) @@ -5700,7 +5709,11 @@ doterm(struct bbslist *bbs) * the next iteration to run promptly — self-wake so the * WaitForEvent below returns immediately. Auto-reset * means the signal is consumed by the wait. */ - if (count_data_waiting() > 0) + /* ...but not while the speed gate or a suspend is what is + * holding them: that wake returns at once and the loop spins a + * core until the backlog drains. The 1 ms wait paces those. */ + if (count_data_waiting() > 0 && !cterm_suspended + && (!speed || xp_timer() >= nextchar)) doterm_wake(); /* WaitForEvent rejects NULL with WAIT_FAILED (no sleep), so * fall back to a plain SLEEP if CreateEvent failed at session -- 2.47.3