Skip to content

Commit e2f58f4

Browse files
committed
wallet: Make vpwallets usage thread safe
1 parent 476cb35 commit e2f58f4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434

3535
#include <boost/algorithm/string/replace.hpp>
3636

37-
static std::vector<CWallet*> vpwallets;
37+
static CCriticalSection cs_wallets;
38+
static std::vector<CWallet*> vpwallets GUARDED_BY(cs_wallets);
3839

3940
bool AddWallet(CWallet* wallet)
4041
{
42+
LOCK(cs_wallets);
4143
assert(wallet);
4244
std::vector<CWallet*>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
4345
if (i != vpwallets.end()) return false;
@@ -47,6 +49,7 @@ bool AddWallet(CWallet* wallet)
4749

4850
bool RemoveWallet(CWallet* wallet)
4951
{
52+
LOCK(cs_wallets);
5053
assert(wallet);
5154
std::vector<CWallet*>::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
5255
if (i == vpwallets.end()) return false;
@@ -56,16 +59,19 @@ bool RemoveWallet(CWallet* wallet)
5659

5760
bool HasWallets()
5861
{
62+
LOCK(cs_wallets);
5963
return !vpwallets.empty();
6064
}
6165

6266
std::vector<CWallet*> GetWallets()
6367
{
68+
LOCK(cs_wallets);
6469
return vpwallets;
6570
}
6671

6772
CWallet* GetWallet(const std::string& name)
6873
{
74+
LOCK(cs_wallets);
6975
for (CWallet* wallet : vpwallets) {
7076
if (wallet->GetName() == name) return wallet;
7177
}

0 commit comments

Comments
 (0)