Skip to content

Commit

Permalink
Revert "alias_resolve: switch from explicit map locks to std::atomic"
Browse files Browse the repository at this point in the history
This reverts commit 316f1e4.

RHEL9: only g++ 11 (need 12)
OpenBSD: libc++ not supporting atomic<shared_ptr> at all
  • Loading branch information
jengelh committed Oct 12, 2024
1 parent abc8bf4 commit e059d6c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mda/alias_resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ static std::atomic<bool> 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<std::shared_ptr<alias_map>> xa_alias_map;
static std::atomic<std::shared_ptr<domain_set>> xa_domain_set;
static std::shared_ptr<alias_map> xa_alias_map;
static std::shared_ptr<domain_set> 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;
Expand Down Expand Up @@ -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()
Expand All @@ -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;

Expand Down

0 comments on commit e059d6c

Please sign in to comment.