Moved calling of event callbacks to after the event is added. Now using unique_locks on the list of events to allow event callbacks to safely modify the list of events

checksum-failure-logging
EricLiu2000 2019-08-05 11:40:17 -04:00
parent bf77b7ac3b
commit 9b3d36c8c1
1 changed files with 8 additions and 4 deletions

View File

@ -52,17 +52,21 @@ public:
auto i = downgradedThreads.find(std::this_thread::get_id()); auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end() && i->second) { if(i != downgradedThreads.end() && i->second) {
event.downgradeFromError(); event.downgradeFromError();
runCallbacks(event); std::unique_lock<std::mutex> eventsLock(eventsMutex);
std::lock_guard<std::mutex> lk(eventsMutex);
add_internal_event(event); add_internal_event(event);
// free the lock so that callbacks may modify events
eventsLock.unlock();
runCallbacks(event);
} else { } else {
std::lock_guard<std::mutex> lk(errorsMutex); std::lock_guard<std::mutex> lk(errorsMutex);
add_internal_error(event); add_internal_error(event);
} }
} else { } else {
runCallbacks(event); std::unique_lock<std::mutex> eventsLock(eventsMutex);
std::lock_guard<std::mutex> lk(eventsMutex);
add_internal_event(event); add_internal_event(event);
// free the lock so that callbacks may modify events
eventsLock.unlock();
runCallbacks(event);
} }
} }
void add(APIEvent::Type type, APIEvent::Severity severity, const Device* forDevice = nullptr) { void add(APIEvent::Type type, APIEvent::Severity severity, const Device* forDevice = nullptr) {