Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionQueue.cpp

    r601ef8 rcfb9c5  
    4444#include <boost/date_time/posix_time/posix_time.hpp>
    4545#include <boost/version.hpp>
    46 #include <iterator>
    4746#include <string>
    4847#include <sstream>
     
    6261    AR(new ActionRegistry()),
    6362    history(new ActionHistory),
     63    CurrentAction(0),
    6464#ifndef HAVE_ACTION_THREAD
    6565    lastActionOk(true)
    6666#else
    67     CurrentAction(0),
    6867    lastActionOk(true),
    6968    run_thread(boost::bind(&ActionQueue::run, this)),
     
    8382#ifdef HAVE_ACTION_THREAD
    8483  stop();
    85 
    86   clearTempQueue();
    8784#endif
    8885
     
    114111    std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl;
    115112    World::getInstance().setExitFlag(5);
    116     clearQueue(actionqueue.size()-1);
     113    clearQueue();
    117114    lastActionOk = false;
    118     std::cerr << "Remaining Actions cleared from queue." << std::endl;
     115    std::cerr << "ActionQueue cleared." << std::endl;
    119116  } catch (std::exception &e) {
    120117    pushStatus("FAIL: General exception caught, aborting.");
    121118    World::getInstance().setExitFlag(134);
    122     clearQueue(actionqueue.size()-1);
     119    clearQueue();
    123120    lastActionOk = false;
    124     std::cerr << "Remaining Actions cleared from queue." << std::endl;
     121    std::cerr << "ActionQueue cleared." << std::endl;
    125122  }
    126123  if (lastActionOk) {
     
    130127  }
    131128#else
    132   setRunThreadIdle(CurrentAction == actionqueue.size());
     129  {
     130    boost::lock_guard<boost::mutex> lock(mtx_idle);
     131    run_thread_isIdle = (CurrentAction == actionqueue.size());
     132  }
    133133  mtx_queue.unlock();
    134134#endif
     
    144144  mtx_queue.lock();
    145145  tempqueue.push_back( newaction );
    146   setRunThreadIdle( !((CurrentAction != actionqueue.size()) || !tempqueue.empty()) );
     146  {
     147    boost::lock_guard<boost::mutex> lock(mtx_idle);
     148    run_thread_isIdle = !((CurrentAction != actionqueue.size()) || !tempqueue.empty());
     149  }
    147150  mtx_queue.unlock();
    148151#endif
     
    181184        pushStatus("FAIL: Action "+*boost::get_error_info<ActionNameString>(e)+" has failed.");
    182185        World::getInstance().setExitFlag(5);
    183         clearQueue(CurrentAction);
    184         clearTempQueue();
     186        clearQueue();
    185187        lastActionOk = false;
    186         std::cerr << "Remaining Actions cleared from queue." << std::endl;
     188        std::cerr << "ActionQueue cleared." << std::endl;
     189        CurrentAction = (size_t)-1;
    187190      } catch (std::exception &e) {
    188191        pushStatus("FAIL: General exception caught, aborting.");
    189192        World::getInstance().setExitFlag(134);
    190         clearQueue(CurrentAction);
    191         clearTempQueue();
    192         std::cerr << "Remaining Actions cleared from queue." << std::endl;
     193        clearQueue();
     194        std::cerr << "ActionQueue cleared." << std::endl;
     195        CurrentAction = (size_t)-1;
    193196      }
    194197      if (lastActionOk) {
     
    196199        NOTIFY(ActionQueued);
    197200        _lastchangedaction = actionqueue[CurrentAction];
    198         mtx_queue.lock();
    199         CurrentAction++;
    200         mtx_queue.unlock();
    201201      }
    202202      // access actionqueue, hence using mutex
    203203      mtx_queue.lock();
     204      // step on to next action and check for end
     205      CurrentAction++;
    204206      // insert new actions (before [CurrentAction]) if they have been spawned
    205207      // we must have an extra vector for this, as we cannot change actionqueue
     
    209211      mtx_queue.unlock();
    210212    }
    211     setRunThreadIdle( !((CurrentAction != actionqueue.size()) || !tempqueue.empty()) );
     213    {
     214      boost::lock_guard<boost::mutex> lock(mtx_idle);
     215      run_thread_isIdle = !((CurrentAction != actionqueue.size()) || !tempqueue.empty());
     216    }
    212217    cond_idle.notify_one();
    213218//    LOG(1, "DEBUG: End of ActionQueue's run() loop.");
    214219  } while (!Interrupted);
    215220}
     221#endif
    216222
    217223void ActionQueue::insertTempQueue()
     
    225231}
    226232
     233#ifdef HAVE_ACTION_THREAD
    227234void ActionQueue::wait()
    228235{
     
    309316}
    310317
    311 void ActionQueue::clearQueue(const size_t _fromAction)
    312 {
    313 #ifdef HAVE_ACTION_THREAD
    314   mtx_queue.lock();
    315 #endif
    316   LOG(1, "Removing all Actions from position " << _fromAction << " onward.");
    317   // free all actions still to be called contained in actionqueue
    318   ActionQueue_t::iterator inititer = actionqueue.begin();
    319   std::advance(inititer, _fromAction);
    320   for (ActionQueue_t::iterator iter = inititer; iter != actionqueue.end(); ++iter)
     318void ActionQueue::clearQueue()
     319{
     320  // free all actions contained in actionqueue
     321  for (ActionQueue_t::iterator iter = actionqueue.begin();
     322      !actionqueue.empty(); iter = actionqueue.begin()) {
    321323    delete *iter;
    322   actionqueue.erase(inititer, actionqueue.end());
    323   LOG(1, "There are " << actionqueue.size() << " remaining Actions.");
    324 #ifdef HAVE_ACTION_THREAD
    325   CurrentAction = actionqueue.size();
    326   mtx_queue.unlock();
    327 #endif
    328 }
    329 
    330 #ifdef HAVE_ACTION_THREAD
    331 void ActionQueue::clearTempQueue()
    332 {
     324    actionqueue.erase(iter);
     325  }
    333326  // free all actions contained in tempqueue
    334327  for (ActionQueue_t::iterator iter = tempqueue.begin();
     
    337330    tempqueue.erase(iter);
    338331  }
    339 }
    340 
    341 void ActionQueue::setRunThreadIdle(const bool _flag)
    342 {
     332#ifdef HAVE_ACTION_THREAD
    343333  {
    344334    boost::unique_lock<boost::mutex> lock(mtx_idle);
    345     run_thread_isIdle = _flag;
    346   }
    347 }
    348 #endif
     335    run_thread_isIdle = true;
     336  }
     337#endif
     338}
    349339
    350340const ActionQueue::ActionTokens_t ActionQueue::getListOfActions() const
     
    365355}
    366356
    367 bool ActionQueue::canUndo() const
    368 {
    369   return history->hasUndo();
    370 }
    371 
    372357void ActionQueue::redoLast()
    373358{
     
    375360}
    376361
    377 bool ActionQueue::canRedo() const
    378 {
    379   return history->hasRedo();
    380 }
    381 
    382362
    383363CONSTRUCT_SINGLETON(ActionQueue)
Note: See TracChangeset for help on using the changeset viewer.