aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2023-06-30 18:18:26 +0300
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2023-06-30 18:29:38 +0300
commit3714121907480869bb7e77ebce5810affbdb8bea (patch)
treefa37c4662da564ceca479584cff657546e285c9f
parent795dae827273f5b7e77a65653b40c98b89567ba7 (diff)
downloadbusybox-w32-3714121907480869bb7e77ebce5810affbdb8bea.tar.gz
busybox-w32-3714121907480869bb7e77ebce5810affbdb8bea.tar.bz2
busybox-w32-3714121907480869bb7e77ebce5810affbdb8bea.zip
win32: UTF8 console input: don't spin the CPU
This is a regression from ec99f03ae which changed Read into Peek in order to keep the record at the console queue. However, it failed to take into account that as a result, if no input is pending, that readConsoleInput_utf8 now returns immediately without waiting for input - unlike ReadConsoleInput. Other than incorrectly returning a FALSE value in such case, it also caused a busy-wait loop of windows_read_key and high CPU usage. Fix that by waiting till there's input before the peek. This should make it just like ReadConsoleInput - which idles till there's input.
-rw-r--r--win32/winansi.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index d85b6de23..67fcc17d3 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -1314,9 +1314,11 @@ BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got)
1314 if (u8pos == u8len) { 1314 if (u8pos == u8len) {
1315 DWORD codepoint; 1315 DWORD codepoint;
1316 1316
1317 // peek rather than read to keep the last processed record at 1317 // wait-and-peek rather than read to keep the last processed record
1318 // the console queue until we deliver all of its products, so 1318 // at the console queue until we deliver all of its products, so
1319 // that WaitForSingleObject(handle) shows there's data ready. 1319 // that external WaitForSingleObject(h) shows there's data ready.
1320 if (WaitForSingleObject(h, INFINITE) != WAIT_OBJECT_0)
1321 return FALSE;
1320 if (!PeekConsoleInputW(h, r, 1, got)) 1322 if (!PeekConsoleInputW(h, r, 1, got))
1321 return FALSE; 1323 return FALSE;
1322 if (*got == 0) 1324 if (*got == 0)