Merge pull request #2209 from CodeShark/WalletRegistrationLocks

Wallet registration locks in main.cpp + UnregisterAllWallet() function
This commit is contained in:
Pieter Wuille 2013-06-25 16:33:16 -07:00
commit 4ad73c6b08
3 changed files with 17 additions and 1 deletions

View File

@ -119,7 +119,7 @@ void Shutdown()
} }
bitdb.Flush(true); bitdb.Flush(true);
boost::filesystem::remove(GetPidFile()); boost::filesystem::remove(GetPidFile());
UnregisterWallet(pwalletMain); UnregisterAllWallets();
delete pwalletMain; delete pwalletMain;
} }

View File

@ -99,9 +99,16 @@ void UnregisterWallet(CWallet* pwalletIn)
} }
} }
void UnregisterAllWallets()
{
LOCK(cs_setpwalletRegistered);
setpwalletRegistered.clear();
}
// get the wallet transaction with the given hash (if it exists) // get the wallet transaction with the given hash (if it exists)
bool static GetTransaction(const uint256& hashTx, CWalletTx& wtx) bool static GetTransaction(const uint256& hashTx, CWalletTx& wtx)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
if (pwallet->GetTransaction(hashTx,wtx)) if (pwallet->GetTransaction(hashTx,wtx))
return true; return true;
@ -111,6 +118,7 @@ bool static GetTransaction(const uint256& hashTx, CWalletTx& wtx)
// erases transaction with the given hash from all wallets // erases transaction with the given hash from all wallets
void static EraseFromWallets(uint256 hash) void static EraseFromWallets(uint256 hash)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->EraseFromWallet(hash); pwallet->EraseFromWallet(hash);
} }
@ -118,6 +126,7 @@ void static EraseFromWallets(uint256 hash)
// make sure all wallets know about the given transaction, in the given block // make sure all wallets know about the given transaction, in the given block
void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate) void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->AddToWalletIfInvolvingMe(hash, tx, pblock, fUpdate); pwallet->AddToWalletIfInvolvingMe(hash, tx, pblock, fUpdate);
} }
@ -125,6 +134,7 @@ void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock*
// notify wallets about a new best chain // notify wallets about a new best chain
void static SetBestChain(const CBlockLocator& loc) void static SetBestChain(const CBlockLocator& loc)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->SetBestChain(loc); pwallet->SetBestChain(loc);
} }
@ -132,6 +142,7 @@ void static SetBestChain(const CBlockLocator& loc)
// notify wallets about an updated transaction // notify wallets about an updated transaction
void static UpdatedTransaction(const uint256& hashTx) void static UpdatedTransaction(const uint256& hashTx)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->UpdatedTransaction(hashTx); pwallet->UpdatedTransaction(hashTx);
} }
@ -139,6 +150,7 @@ void static UpdatedTransaction(const uint256& hashTx)
// dump all wallets // dump all wallets
void static PrintWallets(const CBlock& block) void static PrintWallets(const CBlock& block)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->PrintWallet(block); pwallet->PrintWallet(block);
} }
@ -146,6 +158,7 @@ void static PrintWallets(const CBlock& block)
// notify wallets about an incoming inventory (for request counts) // notify wallets about an incoming inventory (for request counts)
void static Inventory(const uint256& hash) void static Inventory(const uint256& hash)
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->Inventory(hash); pwallet->Inventory(hash);
} }
@ -153,6 +166,7 @@ void static Inventory(const uint256& hash)
// ask wallets to resend their transactions // ask wallets to resend their transactions
void static ResendWalletTransactions() void static ResendWalletTransactions()
{ {
LOCK(cs_setpwalletRegistered);
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->ResendWalletTransactions(); pwallet->ResendWalletTransactions();
} }

View File

@ -119,6 +119,8 @@ struct CBlockTemplate;
void RegisterWallet(CWallet* pwalletIn); void RegisterWallet(CWallet* pwalletIn);
/** Unregister a wallet from core */ /** Unregister a wallet from core */
void UnregisterWallet(CWallet* pwalletIn); void UnregisterWallet(CWallet* pwalletIn);
/** Unregister all wallets from core */
void UnregisterAllWallets();
/** Push an updated transaction to all registered wallets */ /** Push an updated transaction to all registered wallets */
void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false); void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false);