From: Mikko Rasa Date: Mon, 16 Feb 2015 00:17:03 +0000 (+0200) Subject: Turn ArduControl command_queue into a Task X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aa48746158b19ad795a3cc656c4dfe17044baf54;p=r2c2.git Turn ArduControl command_queue into a Task It seems that I was thinking of this back in d5d8ee8, but left it unfinished probably because it was simpler to use a Queue directly. Now some upcoming task management improvements call for it to be a Task. --- diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index 6d75c75..4acfc60 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -702,6 +702,17 @@ bool ArduControl::Queue::empty() const } +bool ArduControl::CommandQueueTask::get_work(PendingCommand &cmd) +{ + return queue.pop(cmd); +} + +void ArduControl::CommandQueueTask::push(const PendingCommand &cmd) +{ + queue.push(cmd); +} + + ArduControl::RefreshTask::RefreshTask(): next(cycle.end()), round(0), @@ -1035,6 +1046,7 @@ ArduControl::ControlThread::ControlThread(ArduControl &c): control(c), done(false) { + tasks.push_back(&control.command_queue); tasks.push_back(&control.monitor); tasks.push_back(&control.mfx_announce); tasks.push_back(&control.mfx_search); @@ -1156,9 +1168,6 @@ void ArduControl::ControlThread::init_baud_rate() bool ArduControl::ControlThread::get_work(PendingCommand &cmd) { - if(control.command_queue.pop(cmd)) - return true; - for(vector::iterator i=tasks.begin(); i!=tasks.end(); ++i) if((*i)->get_work(cmd)) return true; diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index ad14e2d..4373a84 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -241,6 +241,9 @@ private: public: virtual bool get_work(PendingCommand &); + + void push(const PendingCommand &); + bool empty() const { return queue.empty(); } }; class RefreshTask: public Task @@ -387,7 +390,7 @@ private: SensorMap sensors; Msp::Time::TimeDelta command_timeout; - Queue command_queue; + CommandQueueTask command_queue; Queue completed_commands; RefreshTask refresh; S88Task s88;