Changeset 601ef8 for src/Actions
- Timestamp:
- Jan 12, 2015, 10:10:30 PM (10 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 2440ce
- Parents:
- 33c97e
- git-author:
- Frederik Heber <heber@…> (12/14/14 19:10:19)
- git-committer:
- Frederik Heber <heber@…> (01/12/15 22:10:30)
- Location:
- src/Actions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/Action.cpp
r33c97e r601ef8 146 146 endTimer(); 147 147 148 if (shouldUndo() && state != failure){149 if (canUndo()){148 if (shouldUndo() && state != Action::failure) { 149 if (canUndo()) { 150 150 ActionQueue::getInstance().addElement(this,state); 151 151 } -
src/Actions/ActionQueue.cpp
r33c97e r601ef8 44 44 #include <boost/date_time/posix_time/posix_time.hpp> 45 45 #include <boost/version.hpp> 46 #include <iterator> 46 47 #include <string> 47 48 #include <sstream> … … 61 62 AR(new ActionRegistry()), 62 63 history(new ActionHistory), 63 CurrentAction(0),64 64 #ifndef HAVE_ACTION_THREAD 65 65 lastActionOk(true) 66 66 #else 67 CurrentAction(0), 67 68 lastActionOk(true), 68 69 run_thread(boost::bind(&ActionQueue::run, this)), … … 82 83 #ifdef HAVE_ACTION_THREAD 83 84 stop(); 85 86 clearTempQueue(); 84 87 #endif 85 88 … … 111 114 std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl; 112 115 World::getInstance().setExitFlag(5); 113 // clearQueue();116 clearQueue(actionqueue.size()-1); 114 117 lastActionOk = false; 115 // std::cerr << "ActionQueue cleared." << std::endl;118 std::cerr << "Remaining Actions cleared from queue." << std::endl; 116 119 } catch (std::exception &e) { 117 120 pushStatus("FAIL: General exception caught, aborting."); 118 121 World::getInstance().setExitFlag(134); 119 clearQueue( );122 clearQueue(actionqueue.size()-1); 120 123 lastActionOk = false; 121 std::cerr << " ActionQueue cleared." << std::endl;124 std::cerr << "Remaining Actions cleared from queue." << std::endl; 122 125 } 123 126 if (lastActionOk) { … … 127 130 } 128 131 #else 129 { 130 boost::lock_guard<boost::mutex> lock(mtx_idle); 131 run_thread_isIdle = (CurrentAction == actionqueue.size()); 132 } 132 setRunThreadIdle(CurrentAction == actionqueue.size()); 133 133 mtx_queue.unlock(); 134 134 #endif … … 144 144 mtx_queue.lock(); 145 145 tempqueue.push_back( newaction ); 146 { 147 boost::lock_guard<boost::mutex> lock(mtx_idle); 148 run_thread_isIdle = !((CurrentAction != actionqueue.size()) || !tempqueue.empty()); 149 } 146 setRunThreadIdle( !((CurrentAction != actionqueue.size()) || !tempqueue.empty()) ); 150 147 mtx_queue.unlock(); 151 148 #endif … … 184 181 pushStatus("FAIL: Action "+*boost::get_error_info<ActionNameString>(e)+" has failed."); 185 182 World::getInstance().setExitFlag(5); 186 clearQueue(); 183 clearQueue(CurrentAction); 184 clearTempQueue(); 187 185 lastActionOk = false; 188 std::cerr << "ActionQueue cleared." << std::endl; 189 CurrentAction = (size_t)-1; 186 std::cerr << "Remaining Actions cleared from queue." << std::endl; 190 187 } catch (std::exception &e) { 191 188 pushStatus("FAIL: General exception caught, aborting."); 192 189 World::getInstance().setExitFlag(134); 193 clearQueue( );194 std::cerr << "ActionQueue cleared." << std::endl;195 CurrentAction = (size_t)-1;190 clearQueue(CurrentAction); 191 clearTempQueue(); 192 std::cerr << "Remaining Actions cleared from queue." << std::endl; 196 193 } 197 194 if (lastActionOk) { … … 199 196 NOTIFY(ActionQueued); 200 197 _lastchangedaction = actionqueue[CurrentAction]; 198 mtx_queue.lock(); 199 CurrentAction++; 200 mtx_queue.unlock(); 201 201 } 202 202 // access actionqueue, hence using mutex 203 203 mtx_queue.lock(); 204 // step on to next action and check for end205 CurrentAction++;206 204 // insert new actions (before [CurrentAction]) if they have been spawned 207 205 // we must have an extra vector for this, as we cannot change actionqueue … … 211 209 mtx_queue.unlock(); 212 210 } 213 { 214 boost::lock_guard<boost::mutex> lock(mtx_idle); 215 run_thread_isIdle = !((CurrentAction != actionqueue.size()) || !tempqueue.empty()); 216 } 211 setRunThreadIdle( !((CurrentAction != actionqueue.size()) || !tempqueue.empty()) ); 217 212 cond_idle.notify_one(); 218 213 // LOG(1, "DEBUG: End of ActionQueue's run() loop."); 219 214 } while (!Interrupted); 220 215 } 221 #endif222 216 223 217 void ActionQueue::insertTempQueue() … … 231 225 } 232 226 233 #ifdef HAVE_ACTION_THREAD234 227 void ActionQueue::wait() 235 228 { … … 316 309 } 317 310 318 void ActionQueue::clearQueue() 319 { 320 // free all actions contained in actionqueue 321 for (ActionQueue_t::iterator iter = actionqueue.begin(); 322 !actionqueue.empty(); iter = actionqueue.begin()) { 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) 323 321 delete *iter; 324 actionqueue.erase(iter); 325 } 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 { 326 333 // free all actions contained in tempqueue 327 334 for (ActionQueue_t::iterator iter = tempqueue.begin(); … … 330 337 tempqueue.erase(iter); 331 338 } 332 #ifdef HAVE_ACTION_THREAD 339 } 340 341 void ActionQueue::setRunThreadIdle(const bool _flag) 342 { 333 343 { 334 344 boost::unique_lock<boost::mutex> lock(mtx_idle); 335 run_thread_isIdle = true;336 } 337 #endif 338 } 345 run_thread_isIdle = _flag; 346 } 347 } 348 #endif 339 349 340 350 const ActionQueue::ActionTokens_t ActionQueue::getListOfActions() const -
src/Actions/ActionQueue.hpp
r33c97e r601ef8 202 202 void clear(); 203 203 204 /** Clears all actions currently present in the actionqueues. 205 * 206 */ 207 void clearQueue(); 208 209 #ifdef HAVE_ACTION_THREAD 204 /** Clears all actions present in the actionqueues from \a _fromAction. 205 * 206 * @param _fromAction 0 if all Actions to clear or else 207 */ 208 void clearQueue(const size_t _fromAction = 0); 209 210 #ifdef HAVE_ACTION_THREAD 211 212 /** Clears the temporary queue. 213 * 214 */ 215 void clearTempQueue(); 216 217 /** Sets the run_thread_isIdle flag. 218 * 219 * @param _flag state to set to 220 */ 221 void setRunThreadIdle(const bool _flag); 222 210 223 /** Runs the ActionQueue. 211 224 * … … 226 239 */ 227 240 void wait(); 241 242 /** Moves all action from tempqueue into real queue. 243 * 244 */ 245 void insertTempQueue(); 246 228 247 #endif 229 248 … … 236 255 void insertAction(Action *_action, enum Action::QueryOptions state); 237 256 238 /** Moves all action from tempqueue into real queue.239 *240 */241 void insertTempQueue();242 243 257 private: 244 258 /** Private cstor for ActionQueue. … … 267 281 ActionQueue_t actionqueue; 268 282 283 //!> indicates that the last action has failed 284 bool lastActionOk; 285 286 #ifdef HAVE_ACTION_THREAD 269 287 //!> point to current action in actionqueue 270 288 size_t CurrentAction; … … 273 291 ActionQueue_t tempqueue; 274 292 275 //!> indicates that the last action has failed276 bool lastActionOk;277 278 #ifdef HAVE_ACTION_THREAD279 293 //!> internal thread to call Actions 280 294 boost::thread run_thread;
Note:
See TracChangeset
for help on using the changeset viewer.