mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Changed list of events to vector, switched back to using lock_guard instead of shared/unique_locks
This commit is contained in:
@@ -2,11 +2,8 @@
|
||||
#define __ICSNEO_API_EVENTMANAGER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include<map>
|
||||
#include <thread>
|
||||
#include "icsneo/api/event.h"
|
||||
@@ -22,7 +19,7 @@ public:
|
||||
static void ResetInstance();
|
||||
|
||||
size_t eventCount(EventFilter filter = EventFilter()) const {
|
||||
std::shared_lock<std::shared_mutex> lk(mutex);
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
return count_internal(filter);
|
||||
};
|
||||
|
||||
@@ -38,11 +35,11 @@ public:
|
||||
APIEvent getLastError();
|
||||
|
||||
void add(APIEvent event) {
|
||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
add_internal(event);
|
||||
}
|
||||
void add(APIEvent::Type type, APIEvent::Severity severity, const Device* forDevice = nullptr) {
|
||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
add_internal(APIEvent(type, severity, forDevice));
|
||||
}
|
||||
|
||||
@@ -57,14 +54,14 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
eventLimit = newLimit;
|
||||
if(enforceLimit())
|
||||
add_internal(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventWarning));
|
||||
}
|
||||
|
||||
size_t getEventLimit() const {
|
||||
std::shared_lock<std::shared_mutex> lk(mutex);
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
return eventLimit;
|
||||
}
|
||||
|
||||
@@ -74,10 +71,10 @@ private:
|
||||
EventManager& operator=(const EventManager &other);
|
||||
|
||||
// Used by functions for threadsafety
|
||||
mutable std::shared_mutex mutex;
|
||||
mutable std::mutex mutex;
|
||||
|
||||
// Stores all events
|
||||
std::list<APIEvent> events;
|
||||
std::vector<APIEvent> events;
|
||||
std::map<std::thread::id, APIEvent> lastUserErrors;
|
||||
size_t eventLimit = 10000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user