Skip to content

Commit 783bb64

Browse files
committed
Merge #13028: Make vpwallets usage thread safe
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa) Pull request description: This PR turns the functions introduced in #13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in #10740. Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
2 parents 9e9b48d + e2f58f4 commit 783bb64

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)