diff options
author | Jim Posen <jimpo@coinbase.com> | 2017-12-08 10:52:42 -0800 |
---|---|---|
committer | Jim Posen <jimpo@coinbase.com> | 2018-04-25 11:25:09 -0700 |
commit | 70d510d93c08a168407f55c932ab09c644dea3b8 (patch) | |
tree | c20fd2b12e025dedc7e0447d077ac8ae753c1b18 /src/index/txindex.cpp | |
parent | 94b4f8bbb9e7e37f3057b47bf13a74de12b8e0cc (diff) |
[index] Allow TxIndex sync thread to be interrupted.
Diffstat (limited to 'src/index/txindex.cpp')
-rw-r--r-- | src/index/txindex.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index 56966021a9..82798fbcc1 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -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 |