From 53b014781d1451387be174cb836a1957a09b004a Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 3 Feb 2021 11:36:52 +0000 Subject: [PATCH] [misc] improve uprintf() concurrency by using a mutex --- src/rufus.rc | 10 +++++----- src/stdio.c | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/rufus.rc b/src/rufus.rc index 1a4dd45f..3e01bb8e 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -35,7 +35,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 3.14.1734" +CAPTION "Rufus 3.14.1735" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -397,8 +397,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,14,1734,0 - PRODUCTVERSION 3,14,1734,0 + FILEVERSION 3,14,1735,0 + PRODUCTVERSION 3,14,1735,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -416,13 +416,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.14.1734" + VALUE "FileVersion", "3.14.1735" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-3.14.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.14.1734" + VALUE "ProductVersion", "3.14.1735" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index 530adcbb..134c9ef2 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -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)