mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
wallet: Make vpwallets usage thread safe
This commit is contained in:
parent
476cb35551
commit
e2f58f421b
@ -34,10 +34,12 @@
|
|||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#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)
|
bool AddWallet(CWallet* wallet)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_wallets);
|
||||||
assert(wallet);
|
assert(wallet);
|
||||||
std::vector<CWallet*>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
std::vector<CWallet*>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
||||||
if (i != vpwallets.end()) return false;
|
if (i != vpwallets.end()) return false;
|
||||||
@ -47,6 +49,7 @@ bool AddWallet(CWallet* wallet)
|
|||||||
|
|
||||||
bool RemoveWallet(CWallet* wallet)
|
bool RemoveWallet(CWallet* wallet)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_wallets);
|
||||||
assert(wallet);
|
assert(wallet);
|
||||||
std::vector<CWallet*>::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
std::vector<CWallet*>::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
||||||
if (i == vpwallets.end()) return false;
|
if (i == vpwallets.end()) return false;
|
||||||
@ -56,16 +59,19 @@ bool RemoveWallet(CWallet* wallet)
|
|||||||
|
|
||||||
bool HasWallets()
|
bool HasWallets()
|
||||||
{
|
{
|
||||||
|
LOCK(cs_wallets);
|
||||||
return !vpwallets.empty();
|
return !vpwallets.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CWallet*> GetWallets()
|
std::vector<CWallet*> GetWallets()
|
||||||
{
|
{
|
||||||
|
LOCK(cs_wallets);
|
||||||
return vpwallets;
|
return vpwallets;
|
||||||
}
|
}
|
||||||
|
|
||||||
CWallet* GetWallet(const std::string& name)
|
CWallet* GetWallet(const std::string& name)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_wallets);
|
||||||
for (CWallet* wallet : vpwallets) {
|
for (CWallet* wallet : vpwallets) {
|
||||||
if (wallet->GetName() == name) return wallet;
|
if (wallet->GetName() == name) return wallet;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user