mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-11 23:58:18 +00:00
Use CScheduler for wallet flushing, remove ThreadFlushWalletDB
This commit is contained in:
parent
73296f54d6
commit
735d9b5362
@ -1639,7 +1639,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
if (pwalletMain)
|
if (pwalletMain)
|
||||||
pwalletMain->postInitProcess(threadGroup);
|
pwalletMain->postInitProcess(scheduler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return !fRequestShutdown;
|
return !fRequestShutdown;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "primitives/transaction.h"
|
#include "primitives/transaction.h"
|
||||||
#include "script/script.h"
|
#include "script/script.h"
|
||||||
#include "script/sign.h"
|
#include "script/sign.h"
|
||||||
|
#include "scheduler.h"
|
||||||
#include "timedata.h"
|
#include "timedata.h"
|
||||||
#include "txmempool.h"
|
#include "txmempool.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -3754,17 +3755,17 @@ bool CWallet::InitLoadWallet()
|
|||||||
return true;
|
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
|
// Add wallet transactions that aren't already in a block to mempool
|
||||||
// Do this here as mempool requires genesis block to be loaded
|
// Do this here as mempool requires genesis block to be loaded
|
||||||
ReacceptWalletTransactions();
|
ReacceptWalletTransactions();
|
||||||
|
|
||||||
// Run a thread to flush wallet periodically
|
// Run a thread to flush wallet periodically
|
||||||
if (!CWallet::fFlushThreadRunning.exchange(true)) {
|
if (!CWallet::fFlushScheduled.exchange(true)) {
|
||||||
threadGroup.create_thread(ThreadFlushWalletDB);
|
scheduler.scheduleEvery(MaybeFlushWalletDB, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/thread.hpp>
|
|
||||||
|
|
||||||
extern CWallet* pwalletMain;
|
extern CWallet* pwalletMain;
|
||||||
|
|
||||||
@ -79,6 +78,7 @@ class CCoinControl;
|
|||||||
class COutput;
|
class COutput;
|
||||||
class CReserveKey;
|
class CReserveKey;
|
||||||
class CScript;
|
class CScript;
|
||||||
|
class CScheduler;
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
class CWalletTx;
|
class CWalletTx;
|
||||||
|
|
||||||
@ -593,7 +593,7 @@ private:
|
|||||||
class CWallet : public CCryptoKeyStore, public CValidationInterface
|
class CWallet : public CCryptoKeyStore, public CValidationInterface
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::atomic<bool> fFlushThreadRunning;
|
static std::atomic<bool> fFlushScheduled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
||||||
@ -1001,7 +1001,7 @@ public:
|
|||||||
* Wallet post-init setup
|
* Wallet post-init setup
|
||||||
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
|
* 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 */
|
/* Wallets parameter interaction */
|
||||||
static bool ParameterInteraction();
|
static bool ParameterInteraction();
|
||||||
|
@ -777,24 +777,19 @@ DBErrors CWalletDB::ZapWalletTx(vector<CWalletTx>& vWtx)
|
|||||||
return DB_LOAD_OK;
|
return DB_LOAD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadFlushWalletDB()
|
void MaybeFlushWalletDB()
|
||||||
{
|
{
|
||||||
// Make this thread recognisable as the wallet flushing thread
|
static std::atomic<bool> fOneThread;
|
||||||
RenameThread("bitcoin-wallet");
|
if (fOneThread.exchange(true)) {
|
||||||
|
|
||||||
static bool fOneThread;
|
|
||||||
if (fOneThread)
|
|
||||||
return;
|
return;
|
||||||
fOneThread = true;
|
}
|
||||||
if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET))
|
if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int nLastSeen = CWalletDB::GetUpdateCounter();
|
static unsigned int nLastSeen = CWalletDB::GetUpdateCounter();
|
||||||
unsigned int nLastFlushed = CWalletDB::GetUpdateCounter();
|
static unsigned int nLastFlushed = CWalletDB::GetUpdateCounter();
|
||||||
int64_t nLastWalletUpdate = GetTime();
|
static int64_t nLastWalletUpdate = GetTime();
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
MilliSleep(500);
|
|
||||||
|
|
||||||
if (nLastSeen != CWalletDB::GetUpdateCounter())
|
if (nLastSeen != CWalletDB::GetUpdateCounter())
|
||||||
{
|
{
|
||||||
@ -808,7 +803,7 @@ void ThreadFlushWalletDB()
|
|||||||
if (CDB::PeriodicFlush(strFile))
|
if (CDB::PeriodicFlush(strFile))
|
||||||
nLastFlushed = CWalletDB::GetUpdateCounter();
|
nLastFlushed = CWalletDB::GetUpdateCounter();
|
||||||
}
|
}
|
||||||
}
|
fOneThread = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -193,6 +193,6 @@ private:
|
|||||||
void operator=(const CWalletDB&);
|
void operator=(const CWalletDB&);
|
||||||
};
|
};
|
||||||
|
|
||||||
void ThreadFlushWalletDB();
|
void MaybeFlushWalletDB();
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_WALLETDB_H
|
#endif // BITCOIN_WALLET_WALLETDB_H
|
||||||
|
Loading…
Reference in New Issue
Block a user