diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a0519f7942..19aa065bfa 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -48,10 +48,12 @@ #include #include -static std::vector vpwallets; +static CCriticalSection cs_wallets; +static std::vector vpwallets GUARDED_BY(cs_wallets); bool AddWallet(CWallet* wallet) { + LOCK(cs_wallets); assert(wallet); std::vector::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet); if (i != vpwallets.end()) return false; @@ -61,6 +63,7 @@ bool AddWallet(CWallet* wallet) bool RemoveWallet(CWallet* wallet) { + LOCK(cs_wallets); assert(wallet); std::vector::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet); if (i == vpwallets.end()) return false; @@ -70,16 +73,19 @@ bool RemoveWallet(CWallet* wallet) bool HasWallets() { + LOCK(cs_wallets); return !vpwallets.empty(); } std::vector GetWallets() { + LOCK(cs_wallets); return vpwallets; } CWallet* GetWallet(const std::string& name) { + LOCK(cs_wallets); for (CWallet* wallet : vpwallets) { if (wallet->GetName() == name) return wallet; }