mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Revert "Changed list of events to vector, switched back to using lock_guard instead of shared/unique_locks"
This reverts commit 2dac03b3e5.
This commit is contained in:
@@ -16,7 +16,7 @@ void EventManager::ResetInstance() {
|
||||
}
|
||||
|
||||
void EventManager::get(std::vector<APIEvent>& eventOutput, size_t max, EventFilter filter) {
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
||||
|
||||
if(max == 0) // A limit of 0 indicates no limit
|
||||
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
|
||||
*/
|
||||
APIEvent EventManager::getLastError() {
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
||||
|
||||
auto it = lastUserErrors.find(std::this_thread::get_id());
|
||||
if(it == lastUserErrors.end()) {
|
||||
@@ -54,15 +54,10 @@ APIEvent EventManager::getLastError() {
|
||||
}
|
||||
|
||||
void EventManager::discard(EventFilter filter) {
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
|
||||
auto it = events.begin();
|
||||
while(it != events.end()) {
|
||||
if(filter.match(*it))
|
||||
it = events.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
std::unique_lock<std::shared_mutex> lk(mutex);
|
||||
events.remove_if([&filter](const APIEvent& event) {
|
||||
return filter.match(event);
|
||||
});
|
||||
}
|
||||
|
||||
size_t EventManager::count_internal(EventFilter filter) const {
|
||||
@@ -78,15 +73,8 @@ size_t EventManager::count_internal(EventFilter filter) const {
|
||||
* Returns true if any events were removed in the process of doing so.
|
||||
*/
|
||||
bool EventManager::enforceLimit() {
|
||||
// Remove all TooManyEvents before checking. TODO: is this worth doing? not efficient. maybe start from the end and erase any from there
|
||||
auto filter = EventFilter(APIEvent::Type::TooManyEvents);
|
||||
auto it = events.begin();
|
||||
while(it != events.end()) {
|
||||
if(filter.match(*it))
|
||||
it = events.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
// Remove all TooManyEvents before checking
|
||||
events.remove_if([](icsneo::APIEvent err){ return err.getType() == APIEvent::Type::TooManyEvents; });
|
||||
|
||||
// We are not overflowing
|
||||
if(events.size() < eventLimit)
|
||||
|
||||
Reference in New Issue
Block a user