logger: add mutex to deferred logger (#391)

## Link to GitHub Issue, if one exists
[#390 ](https://github.com/spice2x/spice2x.github.io/pull/390)

## Description of change
Just like the normal logger, deferred logging can be called from any
component at any time, so accessing the vector needs to be guarded.

## Testing
This commit is contained in:
bicarus-dev
2025-10-02 23:38:11 -07:00
committed by GitHub
parent 32801319fa
commit cffee2b7f8
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -1743,7 +1743,7 @@ namespace avs {
deferredlogs::defer_error_messages({ deferredlogs::defer_error_messages({
"AVS filesystem initialization failure was previously detected during boot!", "AVS filesystem initialization failure was previously detected during boot!",
fmt::format(" ERROR: directory could not be created: {}", src_path.string().c_str()), fmt::format(" ERROR: directory could not be created: {}", src_path.string().c_str()),
fmt::format(" this crash may have been caused by bad <mounttable> contents in {}", avs::core::CFG_PATH.c_str()), fmt::format(" if you see a crash, it may have been caused by bad <mounttable> contents in {}", avs::core::CFG_PATH.c_str()),
" fix the XML file and try again" " fix the XML file and try again"
}); });
} }
+3
View File
@@ -13,15 +13,18 @@ namespace deferredlogs {
" double check your spice audio options/patches, and try again" " double check your spice audio options/patches, and try again"
}; };
std::mutex deferred_errors_mutex;
std::vector<std::vector<std::string>> deferred_errors; std::vector<std::vector<std::string>> deferred_errors;
void defer_error_messages(std::initializer_list<std::string> messages) { void defer_error_messages(std::initializer_list<std::string> messages) {
std::unique_lock<std::mutex> lock(deferred_errors_mutex);
deferred_errors.emplace_back(messages); deferred_errors.emplace_back(messages);
} }
void dump_to_logger() { void dump_to_logger() {
static std::once_flag printed; static std::once_flag printed;
std::call_once(printed, []() { std::call_once(printed, []() {
std::unique_lock<std::mutex> lock(deferred_errors_mutex);
if (!deferred_errors.empty()) { if (!deferred_errors.empty()) {
log_warning("deferred_error", log_warning("deferred_error",
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");