aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-02-08 13:19:18 -0500
committerMatt Corallo <git@bluematt.me>2017-03-06 18:35:19 -0500
commit735d9b5362aeca34c0e62006986fe9d82c24ca08 (patch)
tree25e2a8ba6b29162ba94520e67f60b9f805e51f7d /src/wallet
parent73296f54d6f0b38fcac627882d2e9480a2bad14a (diff)
Use CScheduler for wallet flushing, remove ThreadFlushWalletDB
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.cpp9
-rw-r--r--src/wallet/wallet.h6
-rw-r--r--src/wallet/walletdb.cpp45
-rw-r--r--src/wallet/walletdb.h2
4 files changed, 29 insertions, 33 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 02af1bf10f..88dbb77ab5 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -20,6 +20,7 @@
#include "primitives/transaction.h"
#include "script/script.h"
#include "script/sign.h"
+#include "scheduler.h"
#include "timedata.h"
#include "txmempool.h"
#include "util.h"
@@ -3754,17 +3755,17 @@ bool CWallet::InitLoadWallet()
return true;
}
-std::atomic<bool> CWallet::fFlushThreadRunning(false);
+std::atomic<bool> CWallet::fFlushScheduled(false);
-void CWallet::postInitProcess(boost::thread_group& threadGroup)
+void CWallet::postInitProcess(CScheduler& scheduler)
{
// Add wallet transactions that aren't already in a block to mempool
// Do this here as mempool requires genesis block to be loaded
ReacceptWalletTransactions();
// Run a thread to flush wallet periodically
- if (!CWallet::fFlushThreadRunning.exchange(true)) {
- threadGroup.create_thread(ThreadFlushWalletDB);
+ if (!CWallet::fFlushScheduled.exchange(true)) {
+ scheduler.scheduleEvery(MaybeFlushWalletDB, 500);
}
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 65ad3e0095..1007934909 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -29,7 +29,6 @@
#include <vector>
#include <boost/shared_ptr.hpp>
-#include <boost/thread.hpp>
extern CWallet* pwalletMain;
@@ -79,6 +78,7 @@ class CCoinControl;
class COutput;
class CReserveKey;
class CScript;
+class CScheduler;
class CTxMemPool;
class CWalletTx;
@@ -593,7 +593,7 @@ private:
class CWallet : public CCryptoKeyStore, public CValidationInterface
{
private:
- static std::atomic<bool> fFlushThreadRunning;
+ static std::atomic<bool> fFlushScheduled;
/**
* Select a set of coins such that nValueRet >= nTargetValue and at least
@@ -1001,7 +1001,7 @@ public:
* Wallet post-init setup
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
*/
- void postInitProcess(boost::thread_group& threadGroup);
+ void postInitProcess(CScheduler& scheduler);
/* Wallets parameter interaction */
static bool ParameterInteraction();
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index f894a365ac..ae95fc4f29 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -777,38 +777,33 @@ DBErrors CWalletDB::ZapWalletTx(vector<CWalletTx>& vWtx)
return DB_LOAD_OK;
}
-void ThreadFlushWalletDB()
+void MaybeFlushWalletDB()
{
- // Make this thread recognisable as the wallet flushing thread
- RenameThread("bitcoin-wallet");
-
- static bool fOneThread;
- if (fOneThread)
+ static std::atomic<bool> fOneThread;
+ if (fOneThread.exchange(true)) {
return;
- fOneThread = true;
- if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET))
+ }
+ if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
return;
+ }
- unsigned int nLastSeen = CWalletDB::GetUpdateCounter();
- unsigned int nLastFlushed = CWalletDB::GetUpdateCounter();
- int64_t nLastWalletUpdate = GetTime();
- while (true)
- {
- MilliSleep(500);
+ static unsigned int nLastSeen = CWalletDB::GetUpdateCounter();
+ static unsigned int nLastFlushed = CWalletDB::GetUpdateCounter();
+ static int64_t nLastWalletUpdate = GetTime();
- if (nLastSeen != CWalletDB::GetUpdateCounter())
- {
- nLastSeen = CWalletDB::GetUpdateCounter();
- nLastWalletUpdate = GetTime();
- }
+ if (nLastSeen != CWalletDB::GetUpdateCounter())
+ {
+ nLastSeen = CWalletDB::GetUpdateCounter();
+ nLastWalletUpdate = GetTime();
+ }
- if (nLastFlushed != CWalletDB::GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2)
- {
- const std::string& strFile = pwalletMain->strWalletFile;
- if (CDB::PeriodicFlush(strFile))
- nLastFlushed = CWalletDB::GetUpdateCounter();
- }
+ if (nLastFlushed != CWalletDB::GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2)
+ {
+ const std::string& strFile = pwalletMain->strWalletFile;
+ if (CDB::PeriodicFlush(strFile))
+ nLastFlushed = CWalletDB::GetUpdateCounter();
}
+ fOneThread = false;
}
//
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h
index 6b847cedbc..85364c134d 100644
--- a/src/wallet/walletdb.h
+++ b/src/wallet/walletdb.h
@@ -193,6 +193,6 @@ private:
void operator=(const CWalletDB&);
};
-void ThreadFlushWalletDB();
+void MaybeFlushWalletDB();
#endif // BITCOIN_WALLET_WALLETDB_H