Changeset 6bbdfb for src/Actions/ActionQueue.cpp
- Timestamp:
- Jan 30, 2015, 1:54:37 PM (10 years ago)
- Parents:
- 419fa2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/ActionQueue.cpp
r419fa2 r6bbdfb 67 67 lastActionOk(true), 68 68 CurrentAction(0), 69 run_thread_isIdle(true), 70 run_thread_running(false), 71 run_thread(boost::bind(&ActionQueue::run, this)) 69 run_thread_isIdle(true) 72 70 #endif 73 71 { … … 105 103 newaction->prepare(state); 106 104 #ifdef HAVE_ACTION_THREAD 105 { 106 boost::mutex::scoped_lock trylock(mtx_run_thread_running, boost::try_to_lock); 107 if (trylock) { 108 trylock.unlock(); 109 run_thread = boost::thread(&ActionQueue::run, this); 110 } 111 } 112 107 113 mtx_actionqueue.lock(); 108 114 #endif … … 144 150 } 145 151 152 void ActionQueue::setActionQueueDone() 153 { 154 boost::lock_guard<boost::mutex> lock(mtx_actionqueue); 155 CurrentAction = actionqueue.size(); 156 } 157 146 158 bool ActionQueue::isTempQueueDone() const 147 159 { … … 173 185 void ActionQueue::run() 174 186 { 175 { 176 boost::lock_guard<boost::mutex> lock(mtx_run_thread_isIdle); 177 run_thread_running = true; 178 } 187 // only a single thread may run this 188 boost::mutex::scoped_lock trylock(mtx_run_thread_running, boost::try_to_lock); 189 if (trylock) { 179 190 bool Interrupted = false; 180 191 do { … … 207 218 lastActionOk = false; 208 219 std::cerr << "Remaining Actions cleared from queue." << std::endl; 209 } catch (std::exception &e) {220 } /* catch (std::exception &e) { 210 221 pushStatus("FAIL: General exception caught, aborting."); 211 222 World::getInstance().setExitFlag(134); 223 lastActionOk = false; 212 224 std::cerr << "Remaining Actions cleared from queue." << std::endl; 213 } 214 // remember action we jus eexecuted225 }*/ 226 // remember action we just executed 215 227 const Action *lastaction = actionqueue[CurrentAction]; 216 // step on to next action and check for end228 // step on to next action if last ok 217 229 if (lastActionOk) 218 230 CurrentAction++; 231 232 mtx_actionqueue.unlock(); 233 234 // remove following Actions outside mutex if current failed 235 if (!lastActionOk) { 236 clearQueue(CurrentAction); // was not incremented 237 clearTempQueue(); 238 setActionQueueDone(); 239 } 240 219 241 // insert new actions (before [CurrentAction]) if they have been spawned 220 242 // we must have an extra vector for this, as we cannot change actionqueue 221 243 // while an action instance is "in-use" 222 mtx_actionqueue.unlock();223 224 if (!lastActionOk) {225 clearQueue(CurrentAction);226 clearTempQueue();227 }228 244 229 245 insertTempQueue(); 230 246 231 // set last action 247 // set last action when all is done for this Action call 232 248 if (lastActionOk) { 233 249 OBSERVE; … … 243 259 cond_idle.notify_one(); 244 260 // LOG(1, "DEBUG: End of ActionQueue's run() loop."); 245 } while (!Interrupted); 246 { 247 boost::lock_guard<boost::mutex> lock(mtx_run_thread_isIdle); 248 run_thread_running = false; 261 } while ((!Interrupted) && (!isActionQueueDone())); 262 trylock.unlock(); 249 263 } 250 264 } … … 277 291 void ActionQueue::wait() 278 292 { 279 if (run_thread_running) { 293 boost::mutex::scoped_lock trylock(mtx_run_thread_running, boost::try_to_lock); 294 if (!trylock) { 280 295 boost::unique_lock<boost::mutex> lock(mtx_run_thread_isIdle); 281 296 while(!run_thread_isIdle) … … 374 389 actionqueue.erase(inititer, actionqueue.end()); 375 390 LOG(1, "There are " << actionqueue.size() << " remaining Actions."); 376 #ifdef HAVE_ACTION_THREAD377 CurrentAction = actionqueue.size();378 #endif379 391 } 380 392 }
Note:
See TracChangeset
for help on using the changeset viewer.