Skip to content

Commit fb0c934

Browse files
committed
Wallet: Let the interval-flushing thread figure out the filename
1 parent bfc7aad commit fb0c934

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3549,14 +3549,18 @@ bool CWallet::InitLoadWallet()
35493549
return true;
35503550
}
35513551

3552+
std::atomic<bool> CWallet::fFlushThreadRunning(false);
3553+
35523554
void CWallet::postInitProcess(boost::thread_group& threadGroup)
35533555
{
35543556
// Add wallet transactions that aren't already in a block to mempool
35553557
// Do this here as mempool requires genesis block to be loaded
35563558
ReacceptWalletTransactions();
35573559

35583560
// Run a thread to flush wallet periodically
3559-
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(this->strWalletFile)));
3561+
if (!CWallet::fFlushThreadRunning.exchange(true)) {
3562+
threadGroup.create_thread(ThreadFlushWalletDB);
3563+
}
35603564
}
35613565

35623566
bool CWallet::ParameterInteraction()

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "wallet/rpcwallet.h"
1919

2020
#include <algorithm>
21+
#include <atomic>
2122
#include <map>
2223
#include <set>
2324
#include <stdexcept>
@@ -550,6 +551,8 @@ class CAccountingEntry
550551
class CWallet : public CCryptoKeyStore, public CValidationInterface
551552
{
552553
private:
554+
static std::atomic<bool> fFlushThreadRunning;
555+
553556
/**
554557
* Select a set of coins such that nValueRet >= nTargetValue and at least
555558
* all coins from coinControl are selected; Never select unconfirmed coins

src/wallet/walletdb.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx)
768768
return DB_LOAD_OK;
769769
}
770770

771-
void ThreadFlushWalletDB(const string& strFile)
771+
void ThreadFlushWalletDB()
772772
{
773773
// Make this thread recognisable as the wallet flushing thread
774774
RenameThread("bitcoin-wallet");
@@ -810,6 +810,7 @@ void ThreadFlushWalletDB(const string& strFile)
810810
if (nRefCount == 0)
811811
{
812812
boost::this_thread::interruption_point();
813+
const std::string& strFile = pwalletMain->strWalletFile;
813814
map<string, int>::iterator _mi = bitdb.mapFileUseCount.find(strFile);
814815
if (_mi != bitdb.mapFileUseCount.end())
815816
{

src/wallet/walletdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,6 @@ class CWalletDB : public CDB
182182

183183
};
184184

185-
void ThreadFlushWalletDB(const std::string& strFile);
185+
void ThreadFlushWalletDB();
186186

187187
#endif // BITCOIN_WALLET_WALLETDB_H

0 commit comments

Comments
 (0)