[misc] improve uprintf() concurrency by using a mutex

This commit is contained in:
Pete Batard 2021-02-03 11:36:52 +00:00
parent 20b8a84595
commit 53b014781d
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
2 changed files with 13 additions and 5 deletions

View file

@ -43,6 +43,7 @@
HWND hStatus;
size_t ubuffer_pos = 0;
char ubuffer[UBUFFER_SIZE]; // Buffer for ubpushf() messages we don't log right away
static HANDLE print_mutex = NULL;
void _uprintf(const char *format, ...)
{
@ -52,6 +53,11 @@ void _uprintf(const char *format, ...)
va_list args;
int n;
if (print_mutex == NULL)
print_mutex = CreateMutex(NULL, FALSE, NULL);
if (WaitForSingleObject(print_mutex, INFINITE) != WAIT_OBJECT_0)
return;
va_start(args, format);
n = safe_vsnprintf(p, sizeof(buf)-3, format, args); // buf-3 is room for CR/LF/NUL
va_end(args);
@ -78,6 +84,8 @@ void _uprintf(const char *format, ...)
Edit_Scroll(hLog, Edit_GetLineCount(hLog), 0);
}
free(wbuf);
ReleaseMutex(print_mutex);
}
void _uprintfs(const char* str)