2 #include "logging/logging.h"
8 std::lock_guard<std::mutex> lock(m_);
9 if (set_paused && state_ == State::kRunning) {
10 state_ = State::kPaused;
11 }
else if (!set_paused && state_ == State::kPaused) {
12 state_ = State::kRunning;
23 std::lock_guard<std::mutex> g(m_);
24 if (state_ == State::kAborted) {
27 state_ = State::kAborted;
34 std::unique_lock<std::mutex> lk(m_);
36 cv_.wait(lk, [
this] {
return state_ != State::kPaused; });
38 return state_ == State::kRunning;
41 void FlowControlToken::reset() {
42 std::lock_guard<std::mutex> g(m_);
43 state_ = State::kRunning;
46 CommandQueue::~CommandQueue() {
49 }
catch (std::exception& ex) {
50 LOG_ERROR <<
"~CommandQueue() exception: " << ex.what() << std::endl;
52 LOG_ERROR <<
"~CommandQueue() unknown exception" << std::endl;
56 void CommandQueue::run() {
57 std::lock_guard<std::mutex> g(thread_m_);
58 if (!thread_.joinable()) {
59 thread_ = std::thread([
this] {
60 std::unique_lock<std::mutex> lock(m_);
62 cv_.wait(lock, [
this] {
return (!queue_.empty() && !paused_) || shutdown_; });
66 auto task = std::move(queue_.front());
76 bool CommandQueue::pause(
bool do_pause) {
79 std::lock_guard<std::mutex> lock(m_);
80 has_effect = paused_ != do_pause;
89 void CommandQueue::abort(
bool restart_thread) {
91 std::lock_guard<std::mutex> thread_g(thread_m_);
93 std::lock_guard<std::mutex> g(m_);
98 if (thread_.joinable()) {
103 std::lock_guard<std::mutex> g(m_);
104 std::queue<std::packaged_task<void()>>().swap(queue_);
109 if (restart_thread) {