Skip to content

Commit

Permalink
thcrap: Fix logging thread using excessive CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
zero318 committed Jun 17, 2024
1 parent 064765a commit 92594f3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions thcrap/src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ static void log_print_real(const char* str, uint32_t n, bool is_n) {
if unexpected(console_open) {
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), str, n, &byteRet, NULL);
}
if (log_file) {
WriteFile(log_file, str, n, &byteRet, NULL);
if (HANDLE file = log_file) {
WriteFile(file, str, n, &byteRet, NULL);
}
if (!is_n) {
if (log_print_hook) {
log_print_hook(str);
if (auto func = log_print_hook) {
func(str);
}
} else {
if (log_nprint_hook) {
log_nprint_hook(str, n);
if (auto func = log_nprint_hook) {
func(str, n);
}
}
}
Expand All @@ -125,7 +125,7 @@ static DWORD WINAPI log_thread(LPVOID lpParameter) {
if (log_queue.empty()) {
log_is_empty = true;
ReleaseSRWLockExclusive(&queue_srwlock);
while (log_is_empty) Sleep(0);
while (log_is_empty) Sleep(10);
} else {
log_string_t log_str = std::move(log_queue.front());
log_queue.pop();
Expand Down

0 comments on commit 92594f3

Please sign in to comment.