diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-04-30 17:19:00 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-04-30 17:26:30 +0200 |
commit | 783bb6455e18c91ede19c7fa62566347066c90e2 (patch) | |
tree | 06d24628085917f222592e92f8f82bfe99487bd5 /src | |
parent | 9e9b48df72dbd68a827f984861779e1c6bd842a4 (diff) | |
parent | e2f58f421b1a6e360bbf7efdfbba398918ce19d3 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/wallet.cpp | 8 |
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; } |