Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shared mutex for fowrard_response_callback #343

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Service/KeeperDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_mutex> 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;
Expand Down Expand Up @@ -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<std::shared_mutex> write_lock(forward_response_callbacks_mutex);

if (forward_response_callbacks.contains(client_id))
{
Expand All @@ -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<std::shared_mutex> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/Service/KeeperDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class KeeperDispatcher : public std::enable_shared_from_this<KeeperDispatcher>
using ForwardResponseCallbacks = std::unordered_map<ForwardClientId, ForwardResponseCallback, PairHash>;

ForwardResponseCallbacks forward_response_callbacks;
std::mutex forward_response_callbacks_mutex;
std::shared_mutex forward_response_callbacks_mutex;

using UpdateConfigurationQueue = ConcurrentBoundedQueue<ConfigUpdateAction>;
/// More than 1k updates is definitely misconfiguration.
Expand Down
Loading