fix getch spin

This commit is contained in:
Lion Kortlepel 2020-11-17 23:10:19 +01:00
parent 04de729d7c
commit a78f65b274
2 changed files with 12 additions and 3 deletions

View File

@ -174,11 +174,19 @@ static void ProcessCompositeInput() {
} }
} }
[[noreturn]] void ReadCin() { void ReadCin() {
DebugPrintTID(); DebugPrintTID();
size_t null_byte_counter = 0;
while (true) { while (true) {
int In = _getch(); int In = _getch();
// info(std::to_string(In)); info(std::to_string(In));
if (In == 0) {
++null_byte_counter;
if (null_byte_counter > 0) {
info("too many null bytes in input, this is now assumed to be a background thread - console input is now disabled");
break;
}
}
if (CompositeInputExpected) { if (CompositeInputExpected) {
CompositeInput += char(In); CompositeInput += char(In);
#ifdef WIN32 #ifdef WIN32

View File

@ -10,6 +10,7 @@
#include <mutex> #include <mutex>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <unistd.h>
#include <unordered_map> #include <unordered_map>
static RWMutex ThreadNameMapMutex; static RWMutex ThreadNameMapMutex;
@ -94,7 +95,7 @@ void DebugPrintTIDInternal(const std::string& func, bool overwrite) {
#ifdef DEBUG #ifdef DEBUG
std::scoped_lock Guard(LogLock); std::scoped_lock Guard(LogLock);
std::stringstream Print; std::stringstream Print;
Print << "(debug build) Thread '" << std::this_thread::get_id() << "' is " << func << "\n"; Print << "(debug build) Thread '" << std::this_thread::get_id() << "' / '" << gettid() << "' is " << func << "\n";
ConsoleOut(Print.str()); ConsoleOut(Print.str());
#endif // DEBUG #endif // DEBUG
} }