mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
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
This commit is contained in:
@@ -52,17 +52,21 @@ public:
|
||||
auto i = downgradedThreads.find(std::this_thread::get_id());
|
||||
if(i != downgradedThreads.end() && i->second) {
|
||||
event.downgradeFromError();
|
||||
runCallbacks(event);
|
||||
std::lock_guard<std::mutex> lk(eventsMutex);
|
||||
std::unique_lock<std::mutex> eventsLock(eventsMutex);
|
||||
add_internal_event(event);
|
||||
// free the lock so that callbacks may modify events
|
||||
eventsLock.unlock();
|
||||
runCallbacks(event);
|
||||
} else {
|
||||
std::lock_guard<std::mutex> lk(errorsMutex);
|
||||
add_internal_error(event);
|
||||
}
|
||||
} else {
|
||||
runCallbacks(event);
|
||||
std::lock_guard<std::mutex> lk(eventsMutex);
|
||||
std::unique_lock<std::mutex> eventsLock(eventsMutex);
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user