From 8471be5017dccb3288155a85850e7ae269a878ac Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Mon, 27 Jun 2022 15:34:37 +0200 Subject: [PATCH] wallet: use Synced for g_loading_wallet_set and remove g_loading_wallet_mutex Convert `g_loading_wallet_set` to use `Synced` and ditch the global mutex `g_loading_wallet_mutex`. --- src/wallet/wallet.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c240e885312200..b2820400a62a66 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -212,10 +212,9 @@ void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr& } } -static GlobalMutex g_loading_wallet_mutex; static GlobalMutex g_wallet_release_mutex; static std::condition_variable g_wallet_release_cv; -static std::set g_loading_wallet_set GUARDED_BY(g_loading_wallet_mutex); +static Synced> g_loading_wallet_set; static std::set g_unloading_wallet_set GUARDED_BY(g_wallet_release_mutex); // Custom deleter for shared_ptr. @@ -359,14 +358,14 @@ class FastWalletRescanFilter std::shared_ptr LoadWallet(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector& warnings) { - auto result = WITH_LOCK(g_loading_wallet_mutex, return g_loading_wallet_set.insert(name)); + auto result = WITH_SYNCED_LOCK(g_loading_wallet_set, p, return p->insert(name)); if (!result.second) { error = Untranslated("Wallet already loading."); status = DatabaseStatus::FAILED_LOAD; return nullptr; } auto wallet = LoadWalletInternal(context, name, load_on_start, options, status, error, warnings); - WITH_LOCK(g_loading_wallet_mutex, g_loading_wallet_set.erase(result.first)); + WITH_SYNCED_LOCK(g_loading_wallet_set, p, p->erase(result.first)); return wallet; }