Changeset 0427d1 for src/Actions/ActionQueue.cpp
- Timestamp:
- Feb 27, 2024, 10:18:17 PM (20 months ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 399c69
- Parents:
- d203d1e
- git-author:
- Frederik Heber <frederik.heber@…> (02/25/24 23:14:04)
- git-committer:
- Frederik Heber <frederik.heber@…> (02/27/24 22:18:17)
- File:
-
- 1 edited
-
src/Actions/ActionQueue.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/ActionQueue.cpp
rd203d1e r0427d1 43 43 44 44 #include <boost/date_time/posix_time/posix_time.hpp> 45 #include <boost/thread/recursive_mutex.hpp> 45 46 #include <boost/version.hpp> 46 47 #include <iterator> … … 147 148 Action *newaction = _action->clone(state); 148 149 newaction->prepare(state); 149 mtx_queue.lock(); 150 tempqueue.push_back( newaction ); 151 const bool tempqueue_notempty = !tempqueue.empty(); 152 mtx_queue.unlock(); 150 bool tempqueue_notempty; 151 { 152 boost::recursive_mutex::scoped_lock lock(mtx_queue); 153 tempqueue.push_back( newaction ); 154 tempqueue_notempty = !tempqueue.empty(); 155 } 153 156 setRunThreadIdle( !((!isIdle()) || tempqueue_notempty) ); 154 157 #endif … … 158 161 { 159 162 #ifdef HAVE_ACTION_THREAD 160 boost:: unique_lock<boost::mutex>lock(mtx_queue);163 boost::recursive_mutex::scoped_lock lock(mtx_queue); 161 164 #endif 162 165 bool status = (CurrentAction == actionqueue.size()); … … 188 191 const Action& ActionQueue::getCurrentAction() const 189 192 { 193 #ifdef HAVE_ACTION_THREAD 194 boost::recursive_mutex::scoped_lock lock(mtx_queue); 195 #endif 190 196 return *const_cast<const Action *>(actionqueue[CurrentAction]); 191 197 } … … 209 215 // LOG(1, "DEBUG: Start of ActionQueue's run() loop."); 210 216 // call all currently present Actions 211 mtx_queue.lock();212 217 insertTempQueue(); 213 mtx_queue.unlock();214 218 bool status = !isIdle(); 215 219 while (status) { 216 220 // boost::this_thread::disable_interruption di; 217 LOG(0, "Calling Action " << actionqueue[CurrentAction]->getName() << " ... ");218 221 try { 219 if (!isDryRun(actionqueue[CurrentAction])) 220 actionqueue[CurrentAction]->call(); 221 pushStatus("SUCCESS: Action "+actionqueue[CurrentAction]->getName()+" successful."); 222 // pick next action to run 223 Action * action_to_run; 224 { 225 boost::recursive_mutex::scoped_lock lock(mtx_queue); 226 action_to_run = actionqueue[CurrentAction]; 227 } 228 LOG(0, "Calling Action " << action_to_run->getName() << " ... "); 229 // run action 230 if (!isDryRun(action_to_run)) 231 action_to_run->call(); 232 pushStatus("SUCCESS: Action "+action_to_run->getName()+" successful."); 222 233 lastActionOk = true; 223 234 } catch(ActionFailureException &e) { … … 239 250 OBSERVE; 240 251 NOTIFY(ActionQueued); 241 _lastchangedaction = actionqueue[CurrentAction]; 242 mtx_queue.lock(); 243 CurrentAction++; 244 mtx_queue.unlock(); 252 stepOnToNextAction(); 245 253 } 246 // access actionqueue, hence using mutex247 mtx_queue.lock();248 254 // insert new actions (before [CurrentAction]) if they have been spawned 249 255 // we must have an extra vector for this, as we cannot change actionqueue 250 256 // while an action instance is "in-use" 251 257 insertTempQueue(); 252 mtx_queue.unlock();253 258 status = !isIdle(); 254 259 } 255 mtx_queue.lock(); 256 const bool tempqueue_notempty = !tempqueue.empty(); 257 mtx_queue.unlock(); 260 bool tempqueue_notempty; 261 { 262 boost::recursive_mutex::scoped_lock lock(mtx_queue); 263 tempqueue_notempty = !tempqueue.empty(); 264 } 258 265 setRunThreadIdle( !((!isIdle()) || tempqueue_notempty) ); 259 266 cond_idle.notify_one(); … … 262 269 } 263 270 271 void ActionQueue::stepOnToNextAction() 272 { 273 boost::recursive_mutex::scoped_lock lock(mtx_queue); 274 _lastchangedaction = actionqueue[CurrentAction]; 275 CurrentAction++; 276 } 277 264 278 void ActionQueue::insertTempQueue() 265 279 { 266 280 if (!tempqueue.empty()) { 267 ActionQueue_t::iterator InsertionIter = actionqueue.begin();268 std::advance(InsertionIter, CurrentAction);269 actionqueue.insert( InsertionIter, tempqueue.begin(), tempqueue.end() );281 // access actionqueue, hence using mutex 282 boost::recursive_mutex::scoped_lock lock(mtx_queue); 283 actionqueue.insert( actionqueue.end(), tempqueue.begin(), tempqueue.end() ); 270 284 tempqueue.clear(); 271 285 } … … 359 373 { 360 374 #ifdef HAVE_ACTION_THREAD 361 mtx_queue.lock();375 boost::recursive_mutex::scoped_lock lock(mtx_queue); 362 376 #endif 363 377 LOG(1, "Removing all Actions from position " << _fromAction << " onward."); … … 371 385 #ifdef HAVE_ACTION_THREAD 372 386 CurrentAction = actionqueue.size(); 373 mtx_queue.unlock();374 387 #endif 375 388 }
Note:
See TracChangeset
for help on using the changeset viewer.
