From 2073d3782ad40ebc7cddf27e73388bb0ce39c077 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 16 Jan 2025 04:16:32 +0300 Subject: [PATCH] fix HandlersList concurrency --- src/util/HandlersList.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/util/HandlersList.hpp b/src/util/HandlersList.hpp index 737fdf36..45882512 100644 --- a/src/util/HandlersList.hpp +++ b/src/util/HandlersList.hpp @@ -14,7 +14,7 @@ namespace util { int nextid = 1; std::unordered_map> handlers; std::vector order; - std::recursive_mutex mutex; + std::mutex mutex; public: HandlersList() = default; @@ -46,11 +46,15 @@ namespace util { } void notify(Types...args) { - std::lock_guard lock(mutex); - - auto orderCopy = order; + std::vector orderCopy; + decltype(handlers) handlersCopy; + { + std::lock_guard lock(mutex); + orderCopy = order; + handlersCopy = handlers; + } for (auto it = orderCopy.rbegin(); it != orderCopy.rend(); ++it) { - if (handlers.at(*it)(args...)) { + if (handlersCopy.at(*it)(args...)) { break; } }