1 #ifndef AKTUALIZR_APIQUEUE_H 2 #define AKTUALIZR_APIQUEUE_H 5 #include <condition_variable> 52 } state_{State::kRunning};
53 mutable std::mutex m_;
54 mutable std::condition_variable cv_;
61 bool pause(
bool do_pause);
62 void abort(
bool restart_thread =
true);
65 std::future<R> enqueue(
const std::function<R()>& f) {
66 std::packaged_task<R()> task(f);
67 auto r = task.get_future();
69 std::lock_guard<std::mutex> lock(m_);
70 queue_.push(std::packaged_task<
void()>(std::move(task)));
78 std::packaged_task<R()> task(std::bind(f, &token_));
79 auto r = task.get_future();
81 std::lock_guard<std::mutex> lock(m_);
82 queue_.push(std::packaged_task<
void()>(std::move(task)));
89 std::atomic_bool shutdown_{
false};
90 std::atomic_bool paused_{
false};
95 std::queue<std::packaged_task<void()>> queue_;
97 std::condition_variable cv_;
102 #endif // AKTUALIZR_APIQUEUE_H Provides a thread-safe way to pause and terminate task execution.
bool canContinue(bool blocking=true) const
Called by the controlled thread to query the currently requested state.
bool setPause(bool set_paused)
Called by the controlling thread to request the task to pause or resume.
bool setAbort()
Called by the controlling thread to request the task to abort.