Skip to content

Commit

Permalink
Merge bitcoin#13028: Make vpwallets usage thread safe
Browse files Browse the repository at this point in the history
e2f58f4 wallet: Make vpwallets usage thread safe (João Barbosa)

Pull request description:

  This PR turns the functions introduced in bitcoin#13017 thread safe. This is required to correctly support dynamically loading wallets, which is implemented in bitcoin#10740.

Tree-SHA512: efaa09e501636cf957aa33de83719ce09dc0c2a19daff741a94ef10d6b7ba5dee538355b80c96ead995140f99f5df0c92fb0e22ae1adb8f397eb478280c8d8c7
  • Loading branch information
laanwj committed Apr 30, 2018
2 parents 9e9b48d + e2f58f4 commit 783bb64
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 783bb64

Please sign in to comment.