mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 02:33:07 +02:00
[index] Allow TxIndex sync thread to be interrupted.
This commit is contained in:
@@ -30,6 +30,12 @@ TxIndex::TxIndex(std::unique_ptr<TxIndexDB> db) :
|
||||
m_db(std::move(db)), m_synced(false), m_best_block_index(nullptr)
|
||||
{}
|
||||
|
||||
TxIndex::~TxIndex()
|
||||
{
|
||||
Interrupt();
|
||||
Stop();
|
||||
}
|
||||
|
||||
bool TxIndex::Init()
|
||||
{
|
||||
LOCK(cs_main);
|
||||
@@ -76,6 +82,11 @@ void TxIndex::ThreadSync()
|
||||
int64_t last_log_time = 0;
|
||||
int64_t last_locator_write_time = 0;
|
||||
while (true) {
|
||||
if (m_interrupt) {
|
||||
WriteBestBlock(pindex);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
const CBlockIndex* pindex_next = NextSyncBlock(pindex);
|
||||
@@ -222,6 +233,11 @@ bool TxIndex::FindTx(const uint256& txid, CDiskTxPos& pos) const
|
||||
return m_db->ReadTxPos(txid, pos);
|
||||
}
|
||||
|
||||
void TxIndex::Interrupt()
|
||||
{
|
||||
m_interrupt();
|
||||
}
|
||||
|
||||
void TxIndex::Start()
|
||||
{
|
||||
// Need to register this ValidationInterface before running Init(), so that
|
||||
|
||||
Reference in New Issue
Block a user