Use CScheduler for wallet flushing, remove ThreadFlushWalletDB

This commit is contained in:
Matt Corallo
2017-02-08 13:19:18 -05:00
parent 73296f54d6
commit 735d9b5362
5 changed files with 34 additions and 38 deletions
+5 -4
View File
@@ -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);
}
}