diff --git a/src/Service/KeeperDispatcher.cpp b/src/Service/KeeperDispatcher.cpp index 16f49d0d23..d7ba240ae0 100644 --- a/src/Service/KeeperDispatcher.cpp +++ b/src/Service/KeeperDispatcher.cpp @@ -152,7 +152,7 @@ void KeeperDispatcher::invokeResponseCallBack(int64_t session_id, const Coordina void KeeperDispatcher::invokeForwardResponseCallBack(ForwardClientId client_id, ForwardResponsePtr response) { - std::lock_guard lock(forward_response_callbacks_mutex); + std::shared_lock read_lock(forward_response_callbacks_mutex); auto forward_response_writer = forward_response_callbacks.find(client_id); if (forward_response_writer == forward_response_callbacks.end()) return; @@ -406,7 +406,7 @@ void KeeperDispatcher::unregisterUserResponseCallBackWithoutLock(int64_t session void KeeperDispatcher::registerForwarderResponseCallBack(ForwardClientId client_id, ForwardResponseCallback callback) { - std::lock_guard lock(forward_response_callbacks_mutex); + std::unique_lock write_lock(forward_response_callbacks_mutex); if (forward_response_callbacks.contains(client_id)) { @@ -426,7 +426,7 @@ void KeeperDispatcher::registerForwarderResponseCallBack(ForwardClientId client_ void KeeperDispatcher::unRegisterForwarderResponseCallBack(ForwardClientId client_id) { - std::lock_guard lock(forward_response_callbacks_mutex); + std::unique_lock write_lock(forward_response_callbacks_mutex); auto forward_response_writer = forward_response_callbacks.find(client_id); if (forward_response_writer == forward_response_callbacks.end()) return; diff --git a/src/Service/KeeperDispatcher.h b/src/Service/KeeperDispatcher.h index b4cb2d620f..49650799c9 100644 --- a/src/Service/KeeperDispatcher.h +++ b/src/Service/KeeperDispatcher.h @@ -64,7 +64,7 @@ class KeeperDispatcher : public std::enable_shared_from_this using ForwardResponseCallbacks = std::unordered_map; ForwardResponseCallbacks forward_response_callbacks; - std::mutex forward_response_callbacks_mutex; + std::shared_mutex forward_response_callbacks_mutex; using UpdateConfigurationQueue = ConcurrentBoundedQueue; /// More than 1k updates is definitely misconfiguration.