mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
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:
@@ -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"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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",
|
||||||
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
|||||||
Reference in New Issue
Block a user