mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Went back to normal mutex because I forgot I reverted those
This commit is contained in:
@@ -16,7 +16,7 @@ void EventManager::ResetInstance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::get(std::vector<APIEvent>& eventOutput, size_t max, EventFilter filter) {
|
void EventManager::get(std::vector<APIEvent>& eventOutput, size_t max, EventFilter filter) {
|
||||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
|
|
||||||
if(max == 0) // A limit of 0 indicates no limit
|
if(max == 0) // A limit of 0 indicates no limit
|
||||||
max = (size_t)-1;
|
max = (size_t)-1;
|
||||||
@@ -41,7 +41,7 @@ void EventManager::get(std::vector<APIEvent>& eventOutput, size_t max, EventFilt
|
|||||||
* If no error was found, return a NoErrorFound Info event
|
* If no error was found, return a NoErrorFound Info event
|
||||||
*/
|
*/
|
||||||
APIEvent EventManager::getLastError() {
|
APIEvent EventManager::getLastError() {
|
||||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
|
|
||||||
auto it = lastUserErrors.find(std::this_thread::get_id());
|
auto it = lastUserErrors.find(std::this_thread::get_id());
|
||||||
if(it == lastUserErrors.end()) {
|
if(it == lastUserErrors.end()) {
|
||||||
@@ -54,7 +54,7 @@ APIEvent EventManager::getLastError() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::discard(EventFilter filter) {
|
void EventManager::discard(EventFilter filter) {
|
||||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
events.remove_if([&filter](const APIEvent& event) {
|
events.remove_if([&filter](const APIEvent& event) {
|
||||||
return filter.match(event);
|
return filter.match(event);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <shared_mutex>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <unordered_map>
|
|
||||||
#include<map>
|
#include<map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "icsneo/api/event.h"
|
#include "icsneo/api/event.h"
|
||||||
@@ -22,7 +20,7 @@ public:
|
|||||||
static void ResetInstance();
|
static void ResetInstance();
|
||||||
|
|
||||||
size_t eventCount(EventFilter filter = EventFilter()) const {
|
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);
|
return count_internal(filter);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -38,11 +36,11 @@ public:
|
|||||||
APIEvent getLastError();
|
APIEvent getLastError();
|
||||||
|
|
||||||
void add(APIEvent event) {
|
void add(APIEvent event) {
|
||||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
add_internal(event);
|
add_internal(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) {
|
||||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
add_internal(APIEvent(type, severity, forDevice));
|
add_internal(APIEvent(type, severity, forDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,14 +55,14 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
eventLimit = newLimit;
|
eventLimit = newLimit;
|
||||||
if(enforceLimit())
|
if(enforceLimit())
|
||||||
add_internal(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventWarning));
|
add_internal(APIEvent(APIEvent::Type::TooManyEvents, APIEvent::Severity::EventWarning));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getEventLimit() const {
|
size_t getEventLimit() const {
|
||||||
std::shared_lock<std::shared_mutex> lk(mutex);
|
std::lock_guard<std::mutex> lk(mutex);
|
||||||
return eventLimit;
|
return eventLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +72,7 @@ private:
|
|||||||
EventManager& operator=(const EventManager &other);
|
EventManager& operator=(const EventManager &other);
|
||||||
|
|
||||||
// Used by functions for threadsafety
|
// Used by functions for threadsafety
|
||||||
mutable std::shared_mutex mutex;
|
mutable std::mutex mutex;
|
||||||
|
|
||||||
// Stores all events
|
// Stores all events
|
||||||
std::list<APIEvent> events;
|
std::list<APIEvent> events;
|
||||||
|
|||||||
Reference in New Issue
Block a user