mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 06:40: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:
@@ -13,15 +13,18 @@ namespace deferredlogs {
|
||||
" double check your spice audio options/patches, and try again"
|
||||
};
|
||||
|
||||
std::mutex deferred_errors_mutex;
|
||||
std::vector<std::vector<std::string>> deferred_errors;
|
||||
|
||||
void defer_error_messages(std::initializer_list<std::string> messages) {
|
||||
std::unique_lock<std::mutex> lock(deferred_errors_mutex);
|
||||
deferred_errors.emplace_back(messages);
|
||||
}
|
||||
|
||||
void dump_to_logger() {
|
||||
static std::once_flag printed;
|
||||
std::call_once(printed, []() {
|
||||
std::unique_lock<std::mutex> lock(deferred_errors_mutex);
|
||||
if (!deferred_errors.empty()) {
|
||||
log_warning("deferred_error",
|
||||
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
|
||||
Reference in New Issue
Block a user