mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-13 17:18:00 +02:00
fuzz: make it possible to mock (fuzz) CThreadInterrupt
* Make the methods of `CThreadInterrupt` virtual and store a pointer to it in `CConnman`, thus making it possible to override with a mocked instance. * Initialize `CConnman::m_interrupt_net` from the constructor, making it possible for callers to supply mocked version. * Introduce `FuzzedThreadInterrupt` and `ConsumeThreadInterrupt()` and use them in `src/test/fuzz/connman.cpp` and `src/test/fuzz/i2p.cpp`. This improves the CPU utilization of the `connman` fuzz test. As a nice side effect, the `std::shared_ptr` used for `CConnman::m_interrupt_net` resolves the possible lifetime issues with it (see the removed comment for that variable).
This commit is contained in:
@@ -9,11 +9,16 @@
|
||||
|
||||
CThreadInterrupt::CThreadInterrupt() : flag(false) {}
|
||||
|
||||
CThreadInterrupt::operator bool() const
|
||||
bool CThreadInterrupt::interrupted() const
|
||||
{
|
||||
return flag.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
CThreadInterrupt::operator bool() const
|
||||
{
|
||||
return interrupted();
|
||||
}
|
||||
|
||||
void CThreadInterrupt::reset()
|
||||
{
|
||||
flag.store(false, std::memory_order_release);
|
||||
|
||||
Reference in New Issue
Block a user