Skip to content

Commit

Permalink
wallet: use Synced<T> for g_loading_wallet_set and remove g_loading_w…
Browse files Browse the repository at this point in the history
…allet_mutex

Convert `g_loading_wallet_set` to use `Synced<T>` and ditch the global mutex
`g_loading_wallet_mutex`.
  • Loading branch information
vasild committed Oct 5, 2023
1 parent c690d03 commit 8471be5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,9 @@ void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>&
}
}

static GlobalMutex g_loading_wallet_mutex;
static GlobalMutex g_wallet_release_mutex;
static std::condition_variable g_wallet_release_cv;
static std::set<std::string> g_loading_wallet_set GUARDED_BY(g_loading_wallet_mutex);
static Synced<std::set<std::string>> g_loading_wallet_set;
static std::set<std::string> g_unloading_wallet_set GUARDED_BY(g_wallet_release_mutex);

// Custom deleter for shared_ptr<CWallet>.
Expand Down Expand Up @@ -359,14 +358,14 @@ class FastWalletRescanFilter

std::shared_ptr<CWallet> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& 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;
}

Expand Down

0 comments on commit 8471be5

Please sign in to comment.