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.h | |
parent | 94b4f8bbb9e7e37f3057b47bf13a74de12b8e0cc (diff) |
[index] Allow TxIndex sync thread to be interrupted.
Diffstat (limited to 'src/index/txindex.h')
-rw-r--r-- | src/index/txindex.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/index/txindex.h b/src/index/txindex.h index 35d58d5b65..633aee46ce 100644 --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -6,6 +6,7 @@ #define BITCOIN_INDEX_TXINDEX_H #include <primitives/block.h> +#include <threadinterrupt.h> #include <txdb.h> #include <uint256.h> #include <validationinterface.h> @@ -31,14 +32,16 @@ private: std::atomic<const CBlockIndex*> m_best_block_index; std::thread m_thread_sync; + CThreadInterrupt m_interrupt; /// Initialize internal state from the database and block index. bool Init(); /// Sync the tx index with the block index starting from the current best - /// block. Intended to be run in its own thread, m_thread_sync. Once the - /// txindex gets in sync, the m_synced flag is set and the BlockConnected - /// ValidationInterface callback takes over and the sync thread exits. + /// block. Intended to be run in its own thread, m_thread_sync, and can be + /// interrupted with m_interrupt. Once the txindex gets in sync, the + /// m_synced flag is set and the BlockConnected ValidationInterface callback + /// takes over and the sync thread exits. void ThreadSync(); /// Write update index entries for a newly connected block. @@ -57,9 +60,14 @@ public: /// Constructs the TxIndex, which becomes available to be queried. explicit TxIndex(std::unique_ptr<TxIndexDB> db); + /// Destructor interrupts sync thread if running and blocks until it exits. + ~TxIndex(); + /// Look up the on-disk location of a transaction by hash. bool FindTx(const uint256& txid, CDiskTxPos& pos) const; + void Interrupt(); + /// Start initializes the sync state and registers the instance as a /// ValidationInterface so that it stays in sync with blockchain updates. void Start(); |