66#define BITCOIN_INDEX_TXINDEX_H
77
88#include < primitives/block.h>
9+ #include < threadinterrupt.h>
910#include < txdb.h>
1011#include < uint256.h>
1112#include < validationinterface.h>
@@ -31,14 +32,16 @@ class TxIndex final : public CValidationInterface
3132 std::atomic<const CBlockIndex*> m_best_block_index;
3233
3334 std::thread m_thread_sync;
35+ CThreadInterrupt m_interrupt;
3436
3537 // / Initialize internal state from the database and block index.
3638 bool Init ();
3739
3840 // / Sync the tx index with the block index starting from the current best
39- // / block. Intended to be run in its own thread, m_thread_sync. Once the
40- // / txindex gets in sync, the m_synced flag is set and the BlockConnected
41- // / ValidationInterface callback takes over and the sync thread exits.
41+ // / block. Intended to be run in its own thread, m_thread_sync, and can be
42+ // / interrupted with m_interrupt. Once the txindex gets in sync, the
43+ // / m_synced flag is set and the BlockConnected ValidationInterface callback
44+ // / takes over and the sync thread exits.
4245 void ThreadSync ();
4346
4447 // / Write update index entries for a newly connected block.
@@ -57,9 +60,14 @@ class TxIndex final : public CValidationInterface
5760 // / Constructs the TxIndex, which becomes available to be queried.
5861 explicit TxIndex (std::unique_ptr<TxIndexDB> db);
5962
63+ // / Destructor interrupts sync thread if running and blocks until it exits.
64+ ~TxIndex ();
65+
6066 // / Look up the on-disk location of a transaction by hash.
6167 bool FindTx (const uint256& txid, CDiskTxPos& pos) const ;
6268
69+ void Interrupt ();
70+
6371 // / Start initializes the sync state and registers the instance as a
6472 // / ValidationInterface so that it stays in sync with blockchain updates.
6573 void Start ();
0 commit comments