From ae7ceffbe451a6264edf7d1354cc9d55df8940b9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 29 Apr 2022 21:00:53 -0700 Subject: Dynamic priority scheme between TTY and FIFO. Whenever a character from the TTY are processed, the work bout size (max number of lines processed without polling TTY or time-of-day) is cut in half, so as the user types, the UI quickly becomes more responsive. When TTY activity ceases, the work bout successively grows in size again toward the maximum value to favor more efficient reading. --- pw.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'pw.c') diff --git a/pw.c b/pw.c index f6c79fc..e3a2b0a 100644 --- a/pw.c +++ b/pw.c @@ -653,7 +653,7 @@ int main(int argc, char **argv) for (unsigned stat = stat_dirty, hpos = 0, kbd_state = kbd_cmd, kbd_prev = kbd_cmd, lasttime = ~0U, - work = 1000, histpos = 0; + workbout = 1024, work = workbout, histpos = 0; kbd_state != kbd_exit ;) { int force = 0, nfds = 2, pollms = poll_interval; @@ -759,7 +759,7 @@ int main(int argc, char **argv) if (pollms == 0 && !force && work-- > 0) continue; - work = 1000; + work = workbout; if (!force) { @@ -794,10 +794,14 @@ int main(int argc, char **argv) drawstatus(columns, stat, curcmd); } } + work = workbout += workbout / 4; } else { if ((pe[0].revents)) { int ch = getc(tty); + if (workbout > 16) + work = workbout /= 2; + if (ch == ctrl('z')) { ttyset(ttyfd, &tty_saved); kill(0, SIGTSTP); @@ -1049,6 +1053,8 @@ int main(int argc, char **argv) clrline(); drawstatus(columns, stat, curcmd); } + } else { + work = workbout += workbout / 4; } } } -- cgit v1.2.3