diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2016-09-09 08:15:01 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2016-11-11 11:35:49 +0000 |
commit | fb0c934d1b2d58b165e13d2b301e54870c5dc60f (patch) | |
tree | 50e25726ca442c99754413e283ac7adca78a8413 | |
parent | bfc7aad0088432b3693a055b0916a869632bdbe2 (diff) | |
download | bitcoin-fb0c934d1b2d58b165e13d2b301e54870c5dc60f.tar.xz |
Wallet: Let the interval-flushing thread figure out the filename
-rw-r--r-- | src/wallet/wallet.cpp | 6 | ||||
-rw-r--r-- | src/wallet/wallet.h | 3 | ||||
-rw-r--r-- | src/wallet/walletdb.cpp | 3 | ||||
-rw-r--r-- | src/wallet/walletdb.h | 2 |
4 files changed, 11 insertions, 3 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c2bac6e330..36b7ddbbc5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3549,6 +3549,8 @@ bool CWallet::InitLoadWallet() return true; } +std::atomic<bool> CWallet::fFlushThreadRunning(false); + void CWallet::postInitProcess(boost::thread_group& threadGroup) { // Add wallet transactions that aren't already in a block to mempool @@ -3556,7 +3558,9 @@ void CWallet::postInitProcess(boost::thread_group& threadGroup) ReacceptWalletTransactions(); // Run a thread to flush wallet periodically - threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(this->strWalletFile))); + if (!CWallet::fFlushThreadRunning.exchange(true)) { + threadGroup.create_thread(ThreadFlushWalletDB); + } } bool CWallet::ParameterInteraction() diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index a527c6d84e..1814870c5e 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -18,6 +18,7 @@ #include "wallet/rpcwallet.h" #include <algorithm> +#include <atomic> #include <map> #include <set> #include <stdexcept> @@ -550,6 +551,8 @@ private: class CWallet : public CCryptoKeyStore, public CValidationInterface { private: + static std::atomic<bool> fFlushThreadRunning; + /** * Select a set of coins such that nValueRet >= nTargetValue and at least * all coins from coinControl are selected; Never select unconfirmed coins diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 43fd6a20ad..9496c4404d 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -768,7 +768,7 @@ DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx) return DB_LOAD_OK; } -void ThreadFlushWalletDB(const string& strFile) +void ThreadFlushWalletDB() { // Make this thread recognisable as the wallet flushing thread RenameThread("bitcoin-wallet"); @@ -810,6 +810,7 @@ void ThreadFlushWalletDB(const string& strFile) if (nRefCount == 0) { boost::this_thread::interruption_point(); + const std::string& strFile = pwalletMain->strWalletFile; map<string, int>::iterator _mi = bitdb.mapFileUseCount.find(strFile); if (_mi != bitdb.mapFileUseCount.end()) { diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index eb25ac613d..efb5e54786 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -182,6 +182,6 @@ private: }; -void ThreadFlushWalletDB(const std::string& strFile); +void ThreadFlushWalletDB(); #endif // BITCOIN_WALLET_WALLETDB_H |