Bitcoin Core 30.99.0
P2P Digital Currency
threadinterrupt.h
Go to the documentation of this file.
1// Copyright (c) 2024-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_TEST_FUZZ_UTIL_THREADINTERRUPT_H
6#define BITCOIN_TEST_FUZZ_UTIL_THREADINTERRUPT_H
7
9#include <util/threadinterrupt.h>
10
11#include <memory>
12
17{
18public:
19 explicit FuzzedThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider);
20
21 virtual bool interrupted() const override;
22 virtual bool sleep_for(Clock::duration) override;
23
24private:
26};
27
28[[nodiscard]] inline std::shared_ptr<CThreadInterrupt> ConsumeThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider)
29{
30 return std::make_shared<FuzzedThreadInterrupt>(fuzzed_data_provider);
31}
32
33#endif // BITCOIN_TEST_FUZZ_UTIL_THREADINTERRUPT_H
A helper class for interruptible sleeps.
Mocked CThreadInterrupt that returns "randomly" whether it is interrupted and never sleeps.
virtual bool interrupted() const override
Return true if operator()() has been called.
virtual bool sleep_for(Clock::duration) override
Sleep for the given duration.
FuzzedThreadInterrupt(FuzzedDataProvider &fuzzed_data_provider)
FuzzedDataProvider & m_fuzzed_data_provider
std::shared_ptr< CThreadInterrupt > ConsumeThreadInterrupt(FuzzedDataProvider &fuzzed_data_provider)