/
githubmirror
/
bitcoin
Обзор
Документация
Войти
/
githubmirror
/
bitcoin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/util/threadinterrupt.h
57 строк
2 KB
Hennadii Stepanov
ci, iwyu: Fix warnings in `src/util` and treat them as errors
30 мар 2026, 18:39
Не верифицирован
30 мар 2026, 18:39
8b49e2d
Код
Авторство
О чём код?
// Copyright (c) 2016-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_UTIL_THREADINTERRUPT_H #define BITCOIN_UTIL_THREADINTERRUPT_H #include <sync.h> #include <util/time.h> #include <atomic> #include <condition_variable> /** * A helper class for interruptible sleeps. Calling operator() will interrupt * any current sleep, and after that point operator bool() will return true * until reset. * * This class should not be used in a signal handler. It uses thread * synchronization primitives that are not safe to use with signals. If sending * an interrupt from a signal handler is necessary, the \ref SignalInterrupt * class can be used instead. */ class CThreadInterrupt { public: using Clock = std::chrono::steady_clock; CThreadInterrupt(); virtual ~CThreadInterrupt() = default; /// Return true if `operator()()` has been called. virtual bool interrupted() const; /// An alias for `interrupted()`. virtual explicit operator bool() const; /// Interrupt any sleeps. After this `interrupted()` will return `true`. virtual void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut); /// Reset to an non-interrupted state. virtual void reset(); /// Sleep for the given duration. /// @retval true The time passed. /// @retval false The sleep was interrupted. virtual bool sleep_for(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut); private: std::condition_variable cond; Mutex mut; std::atomic<bool> flag; }; #endif // BITCOIN_UTIL_THREADINTERRUPT_H