Changeset 1eba7c for src/UIElements


Ignore:
Timestamp:
Apr 25, 2016, 7:05:31 AM (9 years ago)
Author:
Frederik Heber <heber@…>
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:
ea7926
Parents:
efeeb7
git-author:
Frederik Heber <heber@…> (04/18/16 20:57:47)
git-committer:
Frederik Heber <heber@…> (04/25/16 07:05:31)
Message:

Protecting access to atom and bond functions in GLWorldScene with mutexes.

  • mutex are now for general access to internal maps, not just NodesInSceneMap.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    refeeb7 r1eba7c  
    229229  connect(_atom.get(), SIGNAL(moleculeChanged()), this, SLOT(reparentAtom()));
    230230
     231  boost::recursive_mutex::scoped_lock lock(Atom_mutex);
     232
    231233  // store the object, as we need it on reparenting
    232   {
     234  const ObservedValue_Index_t atomid = _atom->getIndex();
    233235#ifndef NDEBUG
    234     std::pair< ObservedAtoms_t::iterator, bool > inserter =
     236  std::pair< ObservedAtoms_t::iterator, bool > inserter =
    235237#endif
    236         ObservedAtoms.insert( std::make_pair(_atom.get(), _atom) );
    237     ASSERT( inserter.second,
    238         "GLWorldScene::connectAtom() - observed atom "+toString(_atom)+" already stored?");
     238      ObservedAtoms.insert( std::make_pair(_atom.get(), _atom) );
     239  ASSERT( inserter.second,
     240      "GLWorldScene::connectAtom() - observed atom "+toString(_atom)+" already stored?");
    239241#ifndef NDEBUG
    240     std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter =
     242  std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter =
    241243#endif
    242         ObservedValueIndexLookup.insert( std::make_pair(_atom->getIndex(), _atom.get()) );
    243     ASSERT( indexinserter.second,
    244         "GLWorldScene::connectAtom() - observed atom's index "
    245         +toString(_atom->getIndex())+" already stored?");
    246   }
    247   {
    248     const ObservedValue_Index_t atomid = _atom->getIndex();
    249     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    250     AtomNodeParentMap.left.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) );
    251   }
     244      ObservedValueIndexLookup.insert( std::make_pair(atomid, _atom.get()) );
     245  ASSERT( indexinserter.second,
     246      "GLWorldScene::connectAtom() - observed atom's index "
     247      +toString(atomid)+" already stored?");
     248
     249  // and create entry in the parent map
     250  AtomNodeParentMap.left.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) );
    252251
    253252  emit atomConnected(_atom);
     
    262261  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "
    263262      << _atom->getAtomIndex());
     263  boost::recursive_mutex::scoped_lock lock(Atom_mutex);
    264264
    265265  const ObservedValue_Index_t atomid = _atom->getIndex();
     
    267267  GLMoleculeObject_atom *atomObject = NULL;
    268268  {
    269     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    270269    AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(atomid);
    271270    ASSERT (parentiter != AtomNodeParentMap.left.end(),
     
    335334void GLWorldScene::checkAndRemoveAtom(const ObservedValue_Index_t &_atomid)
    336335{
    337   boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     336  boost::recursive_mutex::scoped_lock lock(Atom_mutex);
    338337
    339338  if (checkAtomRemoval(AtomNodeParentMap, ToBeRemovedNodes, _atomid)) {
     
    354353  LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
    355354  // bonds are removed by signal coming from ~bond
     355  boost::recursive_mutex::scoped_lock lock(Atom_mutex);
    356356
    357357  ASSERT( ToBeRemovedNodes.count(_atomid) == 0,
     
    381381  connect(_bond.get(), SIGNAL(rightmoleculeChanged()), this, SLOT(reparentBondRight()), Qt::QueuedConnection);
    382382
     383  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
     384
    383385  // store the object, as we need it on reparenting
     386  const ObservedValue_Index_t bondid = _bond->getIndex();
    384387  {
    385388#ifndef NDEBUG
     
    392395    std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter =
    393396#endif
    394         ObservedValueIndexLookup.insert( std::make_pair(_bond->getIndex(), _bond.get()) );
     397        ObservedValueIndexLookup.insert( std::make_pair(bondid, _bond.get()) );
    395398    ASSERT( indexinserter.second,
    396399        "GLWorldScene::connectBond() - observed bond's index "
    397         +toString(_bond->getIndex())+" already stored?");
     400        +toString(bondid)+" already stored?");
    398401  }
    399402  {
    400     const ObservedValue_Index_t bondid = _bond->getIndex();
    401     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    402403    if ((_bond->getLeftAtom() != NULL) && (_bond->getLeftAtom()->getMoleculeRef() != NULL))
    403404      BondNodeParentMaps[0].left.insert(
     
    423424void GLWorldScene::insertBond(QtObservedBond::ptr _bond)
    424425{
    425   static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
     426  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
     427
     428  const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
    426429      boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
    427430          (GLMoleculeObject_bond::left)
     
    436439#endif
    437440  {
    438     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    439441    for (size_t i=0;i<2;++i) {
    440442      BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[i].left.find(bondid);
     
    464466void GLWorldScene::checkAndRemoveBond(const ObservedValue_Index_t &_bondid)
    465467{
     468  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
     469
    466470  if (checkBondRemoval(BondNodeParentMaps, ToBeRemovedNodes, _bondid)) {
    467471    LOG(3, "DEBUG: Found both parents of to be removed bond " << _bondid << " as GLWorldScene, removing.");
     
    479483void GLWorldScene::removeBond(ObservedValue_Index_t _bondid)
    480484{
    481   boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     485  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
    482486  LOG(3, "INFO: GLWorldScene::removedBond() - got bondRemoved signal from board for id " << _bondid);
    483487
     
    495499void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob)
    496500{
     501  boost::recursive_mutex::scoped_lock lock(Atom_mutex);
    497502  // Find the atom, ob corresponds to.
    498503  hoverAtomId = -1;
     
    565570  // check all atoms for not yet assigned parents
    566571  {
    567     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     572    boost::recursive_mutex::scoped_lock lock(Atom_mutex);
    568573    std::pair<AtomNodeParentMap_t::right_const_iterator, AtomNodeParentMap_t::right_const_iterator> iters =
    569574        AtomNodeParentMap.right.equal_range(molid);
     
    577582  // check all bonds for not yet assigned parents
    578583  {
    579     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     584    boost::recursive_mutex::scoped_lock lock(Bond_mutex);
    580585    for (size_t i=0;i<2;++i) {
    581586      std::pair<BondNodeParentMap_t::right_const_iterator, BondNodeParentMap_t::right_const_iterator> iters =
     
    671676void GLWorldScene::reparentAtom()
    672677{
    673   boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     678  boost::recursive_mutex::scoped_lock lock(Atom_mutex);
    674679  QObject * origin = sender();
    675680  if (origin == NULL) {
     
    709714void GLWorldScene::reparentBondLeft()
    710715{
    711   boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     716  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
    712717  QObject * origin = sender();
    713718  if (origin == NULL) {
     
    732737void GLWorldScene::reparentBondRight()
    733738{
    734   boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     739  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
    735740  QObject * origin = sender();
    736741  if (origin == NULL) {
     
    777782    const GLMoleculeObject_bond::SideOfBond _side)
    778783{
    779   boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     784  boost::recursive_mutex::scoped_lock lock(Bond_mutex);
    780785  const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1;
    781786  const ObservedValue_Index_t bondid = _bond->getIndex();
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    refeeb7 r1eba7c  
    170170  atomId_t hoverAtomId;
    171171
    172   //!> mutex to ascertain atomic access to NodeParentMaps
    173   boost::recursive_mutex AtomNodeParentMap_mutex;
    174   boost::recursive_mutex BondNodeParentMap_mutex;
     172  //!> mutex to ascertain atomic access to atom-related internal maps
     173  boost::recursive_mutex Atom_mutex;
     174  //!> mutex to ascertain atomic access to bond-related internal maps
     175  boost::recursive_mutex Bond_mutex;
    175176
    176177  AtomNodeMap AtomsinSceneMap;
Note: See TracChangeset for help on using the changeset viewer.