Error downgrading now uses a map<threadid, bool>, and error downgrading is canceled during message callbacks

checksum-failure-logging
EricLiu2000 2019-07-29 15:16:35 -04:00
parent ff1e65b292
commit 54b98ec9b4
3 changed files with 19 additions and 5 deletions

View File

@ -15,12 +15,23 @@ void EventManager::ResetInstance() {
singleton = std::unique_ptr<EventManager>(new EventManager());
}
// If this thread is not in the map, add it to be ignored
// If it is, set it to be ignored
void EventManager::downgradeErrorsOnCurrentThread() {
downgradedThreads.insert(std::this_thread::get_id());
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end()) {
i->second = true;
} else {
downgradedThreads.insert({std::this_thread::get_id(), true});
}
}
// If this thread exists in the map, turn off downgrading
void EventManager::cancelErrorDowngradingOnCurrentThread() {
downgradedThreads.erase(std::this_thread::get_id());
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end()) {
i->second = false;
}
}
void EventManager::get(std::vector<APIEvent>& eventOutput, size_t max, EventFilter filter) {

View File

@ -113,11 +113,14 @@ void MultiChannelCommunication::readTask() {
continue;
}
// We want callbacks to be able to access errors
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
for(auto& cb : messageCallbacks) { // We might have closed while reading or processing
if(!closing) {
cb.second.callIfMatch(msg);
}
}
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
}
}

View File

@ -2,7 +2,6 @@
#define __ICSNEO_API_EVENTMANAGER_H_
#include <vector>
#include <set>
#include <list>
#include <mutex>
#include <functional>
@ -80,7 +79,7 @@ private:
// Used by functions for threadsafety
mutable std::mutex mutex;
std::set<std::thread::id> downgradedThreads;
std::map<std::thread::id, bool> downgradedThreads;
// Stores all events
std::list<APIEvent> events;
@ -92,7 +91,8 @@ private:
void add_internal(APIEvent event) {
if(event.getSeverity() == APIEvent::Severity::Error) {
// if the error was added on a thread that downgrades errors (non-user thread)
if(std::find(downgradedThreads.begin(), downgradedThreads.end(), std::this_thread::get_id()) != downgradedThreads.end()) {
auto i = downgradedThreads.find(std::this_thread::get_id());
if(i != downgradedThreads.end() && i->second) {
event.downgradeFromError();
add_internal_event(event);
} else