aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2018-04-19 14:44:34 +0100
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2018-04-24 17:26:04 +0100
commite2f58f421b1a6e360bbf7efdfbba398918ce19d3 (patch)
treed57118eef22401dec74fafe31dd191585775db29 /src
parent476cb35551f559573c81a3927856b3f76aecd6e9 (diff)
downloadbitcoin-e2f58f421b1a6e360bbf7efdfbba398918ce19d3.tar.xz
wallet: Make vpwallets usage thread safe
Diffstat (limited to 'src')
-rw-r--r--src/wallet/wallet.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index ad3dd4cd2c..6e0f49f136 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -34,10 +34,12 @@
#include <boost/algorithm/string/replace.hpp>
-static std::vector<CWallet*> vpwallets;
+static CCriticalSection cs_wallets;
+static std::vector<CWallet*> vpwallets GUARDED_BY(cs_wallets);
bool AddWallet(CWallet* wallet)
{
+ LOCK(cs_wallets);
assert(wallet);
std::vector<CWallet*>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
if (i != vpwallets.end()) return false;
@@ -47,6 +49,7 @@ bool AddWallet(CWallet* wallet)
bool RemoveWallet(CWallet* wallet)
{
+ LOCK(cs_wallets);
assert(wallet);
std::vector<CWallet*>::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
if (i == vpwallets.end()) return false;
@@ -56,16 +59,19 @@ bool RemoveWallet(CWallet* wallet)
bool HasWallets()
{
+ LOCK(cs_wallets);
return !vpwallets.empty();
}
std::vector<CWallet*> 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;
}