23#include <condition_variable>
31 :
std::runtime_error(
"ThreadLoopException")
41 const std::function<
void()>& process,
42 const std::function<
void()>& cleanup);
72 std::thread::id threadId_;
80 const std::function<
void()>& process,
81 const std::function<
void()>& cleanup)
89 template<
typename Rep,
typename Period>
92 if (std::this_thread::get_id() !=
get_id())
93 throw std::runtime_error(
"Unable to call wait_for outside thread context");
95 std::unique_lock
lk(mutex_);
99 template<
typename Rep,
typename Period,
typename Pred>
102 if (std::this_thread::get_id() !=
get_id())
103 throw std::runtime_error(
"Unable to call wait_for outside thread context");
105 std::unique_lock
lk(mutex_);
109 template<
typename Pred>
112 if (std::this_thread::get_id() !=
get_id())
113 throw std::runtime_error(
"Unable to call wait outside thread context");
115 std::unique_lock
lk(mutex_);
116 cv_.wait(
lk, [
this, p = std::forward<Pred>(
pred)] {
return isStopping() || p(); });
121 std::condition_variable cv_;
bool wait_for(const std::chrono::duration< Rep, Period > &rel_time, Pred &&pred)
void interrupt() noexcept
void wait_for(const std::chrono::duration< Rep, Period > &rel_time)
InterruptedThreadLoop(const std::function< bool()> &setup, const std::function< void()> &process, const std::function< void()> &cleanup)
bool isStopping() const noexcept
bool isRunning() const noexcept
std::thread::id get_id() const noexcept
void emitSignal(Args... args)