From e059d6c1a18cce2dc76e83cceaaad45e809e0499 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sat, 12 Oct 2024 16:02:23 +0200 Subject: [PATCH] Revert "alias_resolve: switch from explicit map locks to std::atomic" This reverts commit 316f1e44ee8e61f565b2a140792fdfa8b1690fb4. RHEL9: only g++ 11 (need 12) OpenBSD: libc++ not supporting atomic at all --- mda/alias_resolve.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mda/alias_resolve.cpp b/mda/alias_resolve.cpp index 765a44a0e..242480b51 100644 --- a/mda/alias_resolve.cpp +++ b/mda/alias_resolve.cpp @@ -52,8 +52,9 @@ static std::atomic xa_notify_stop{false}; static std::condition_variable xa_thread_wake; static alias_map xa_empty_alias_map; static domain_set xa_empty_domain_set; -static std::atomic> xa_alias_map; -static std::atomic> xa_domain_set; +static std::shared_ptr xa_alias_map; +static std::shared_ptr xa_domain_set; +static std::mutex xa_alias_lock; static std::thread xa_thread; static mysql_adaptor_init_param g_parm; static std::chrono::seconds g_cache_lifetime; @@ -155,10 +156,11 @@ static void xa_refresh_once() auto conn = sql_make_conn(); auto newmap = xa_refresh_aliases(conn); auto newdom = xa_refresh_domains(conn); + std::unique_lock lk(xa_alias_lock); if (newmap != nullptr) - xa_alias_map.exchange(std::move(newmap)); + xa_alias_map = std::move(newmap); if (newdom != nullptr) - xa_domain_set.exchange(std::move(newdom)); + xa_domain_set = std::move(newdom); } static void xa_refresh_thread() @@ -175,8 +177,13 @@ static void xa_refresh_thread() static hook_result xa_alias_subst(MESSAGE_CONTEXT *ctx) try { - auto alias_map_ptr = xa_alias_map.load(); - auto domset_ptr = xa_domain_set.load(); + decltype(xa_alias_map) alias_map_ptr; + decltype(xa_domain_set) domset_ptr; + { + std::unique_lock lk(xa_alias_lock); + alias_map_ptr = xa_alias_map; + domset_ptr = xa_domain_set; + } auto &alias_map = alias_map_ptr != nullptr ? *alias_map_ptr : xa_empty_alias_map; auto &domset = domset_ptr != nullptr ? *domset_ptr : xa_empty_domain_set;