Changeset 354859
- Timestamp:
- Feb 16, 2010, 5:26:59 PM (15 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:
- 7dad10, b1d8092
- Parents:
- 7a1ce5
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/World.cpp
r7a1ce5 r354859 9 9 10 10 #include "atom.hpp" 11 #include "molecule.hpp" 12 #include "periodentafel.hpp" 11 13 #include "Descriptors/AtomDescriptor.hpp" 12 14 … … 14 16 15 17 /******************************* getter and setter ************************/ 16 periodentafel *World::getPeriode(){18 periodentafel *&World::getPeriode(){ 17 19 return periode; 18 20 } … … 26 28 } 27 29 30 int World::numAtoms(){ 31 return atoms.size(); 32 } 33 34 int World::numMolecules(){ 35 return molecules_deprecated->ListOfMolecules.size(); 36 } 37 38 molecule* World::createMolecule(){ 39 OBSERVE; 40 molecule *mol = NULL; 41 mol = new molecule(periode); 42 molecules_deprecated->insert(mol); 43 molecules.insert(mol); 44 mol->signOn(this); 45 return mol; 46 } 47 48 28 49 /******************************* Singleton Stuff **************************/ 29 50 … … 35 56 36 57 World::World() : 37 dummyId(0) 58 dummyId(0), 59 periode(new periodentafel), 60 molecules_deprecated(new MoleculeListClass) 38 61 {} 39 62 40 63 World::~World() 41 {} 64 { 65 delete periode; 66 } 42 67 43 68 World* World::get(){ … … 51 76 52 77 void World::destroy(){ 78 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise 79 theWorld->destroyLegacy(); 80 //WARNING: at this point we have a small race condition, when sombody now tries to access the world. 81 53 82 // boost supports RAII-Style locking, so we don't need to unlock 54 83 boost::mutex::scoped_lock guard(worldLock); … … 58 87 59 88 World* World::reset(){ 89 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise 90 theWorld->destroyLegacy(); 91 //WARNING: at this point we have a small race condition, when sombody now tries to access the world. 92 60 93 World* oldWorld = 0; 61 94 { … … 81 114 /******************************* deprecated Legacy Stuff ***********************/ 82 115 83 MoleculeListClass * World::getMolecules() {84 return molecules ;116 MoleculeListClass *&World::getMolecules() { 117 return molecules_deprecated; 85 118 } 86 119 … … 91 124 } 92 125 126 void World::destroyLegacy(){ 127 //delete molecules_deprecated; 128 } 129 93 130 void World::unregisterAtom(atom *theAtom){ 94 131 OBSERVE; -
src/World.hpp
r7a1ce5 r354859 12 12 #include <map> 13 13 #include <vector> 14 #include <set> 14 15 15 16 #include "Patterns/Observer.hpp" … … 20 21 class MoleculeListClass; 21 22 class atom; 23 class molecule; 22 24 class AtomDescriptor; 23 25 class AtomDescriptor_impl; … … 29 31 30 32 /***** getter and setter *****/ 31 periodentafel* getPeriode(); 33 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object 34 periodentafel *&getPeriode(); 32 35 atom* getAtom(AtomDescriptor descriptor); 33 36 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor); 37 int numAtoms(); 38 int numMolecules(); 39 40 /***** Methods to work with the World *****/ 41 molecule *createMolecule(); 34 42 private: 35 43 periodentafel *periode; 36 44 std::map<int,atom*> atoms; 45 std::set<molecule*> molecules; 37 46 38 47 … … 57 66 *****/ 58 67 public: 59 MoleculeListClass * getMolecules();68 MoleculeListClass *&getMolecules(); 60 69 61 70 // functions used for the WorldContent template mechanism … … 63 72 void unregisterAtom(atom *theAtom); 64 73 private: 65 MoleculeListClass *molecules; 74 // this function cleans up anything that cannot be cleaned while the lock is active 75 // at a later point all these cleanups have to be moved to the World Class so the deadlock and 76 // race condition can both be avoided. 77 void destroyLegacy(); 78 79 MoleculeListClass *molecules_deprecated; 66 80 67 81 // this is needed to assign unique IDs to atoms... so far -
src/builder.cpp
r7a1ce5 r354859 76 76 #include "Actions/MethodAction.hpp" 77 77 #include "Actions/small_actions.hpp" 78 #include "World.hpp" 78 79 #include "version.h" 79 80 … … 2164 2165 /********************************************** Main routine **************************************/ 2165 2166 2167 void cleanUp(config *configuration){ 2168 World::destroy(); 2169 delete(configuration); 2170 Log() << Verbose(0) << "Maximum of allocated memory: " 2171 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2172 Log() << Verbose(0) << "Remaining non-freed memory: " 2173 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2174 MemoryUsageObserver::purgeInstance(); 2175 logger::purgeInstance(); 2176 errorLogger::purgeInstance(); 2177 UIFactory::purgeInstance(); 2178 ActionRegistry::purgeRegistry(); 2179 } 2180 2166 2181 int main(int argc, char **argv) 2167 2182 { 2168 periodentafel *periode = new periodentafel;2169 MoleculeListClass *molecules = new MoleculeListClass;2170 2183 molecule *mol = NULL; 2171 2184 config *configuration = new config; … … 2178 2191 setVerbosity(0); 2179 2192 /* structure of ParseCommandLineOptions will be refactored later */ 2180 j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName);2193 j = ParseCommandLineOptions(argc, argv, World::get()->getMolecules(), World::get()->getPeriode(), *configuration, ConfigFileName); 2181 2194 switch (j){ 2182 2195 case 255: 2183 2196 case 2: 2184 2197 case 1: 2185 delete (molecules); 2186 delete (periode); 2187 delete (configuration); 2188 Log() << Verbose(0) << "Maximum of allocated memory: " << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2189 Log() << Verbose(0) << "Remaining non-freed memory: " << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2190 MemoryUsageObserver::getInstance()->purgeInstance(); 2191 logger::purgeInstance(); 2192 errorLogger::purgeInstance(); 2198 cleanUp(configuration); 2193 2199 return (j == 1 ? 0 : j); 2194 2200 default: 2195 2201 break; 2196 2202 } 2197 if( molecules->ListOfMolecules.size() == 0){2198 mol = new molecule(periode);2203 if(World::get()->numMolecules() == 0){ 2204 mol = World::get()->createMolecule(); 2199 2205 if(mol->cell_size[0] == 0.){ 2200 2206 Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl; … … 2204 2210 } 2205 2211 } 2206 2207 2212 mol->ActiveFlag = true; 2208 molecules->insert(mol);2209 2213 } 2210 2214 … … 2218 2222 2219 2223 UIFactory::makeUserInterface(UIFactory::Text); 2220 MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters, molecules, configuration, periode, ConfigFileName);2224 MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,World::get()->getMolecules(), configuration, World::get()->getPeriode(), ConfigFileName); 2221 2225 mainWindow->display(); 2222 2226 delete mainWindow; 2223 2227 } 2224 2228 2225 if( periode->StorePeriodentafel(configuration->databasepath))2229 if(World::get()->getPeriode()->StorePeriodentafel(configuration->databasepath)) 2226 2230 Log() << Verbose(0) << "Saving of elements.db successful." << endl; 2227 2231 … … 2229 2233 Log() << Verbose(0) << "Saving of elements.db failed." << endl; 2230 2234 2231 delete (molecules); 2232 delete(periode); 2233 delete(configuration); 2234 2235 2236 2237 Log() << Verbose(0) << "Maximum of allocated memory: " 2238 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2239 Log() << Verbose(0) << "Remaining non-freed memory: " 2240 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2241 MemoryUsageObserver::purgeInstance(); 2242 logger::purgeInstance(); 2243 errorLogger::purgeInstance(); 2244 UIFactory::purgeInstance(); 2245 ActionRegistry::purgeRegistry(); 2235 cleanUp(configuration); 2246 2236 return (0); 2247 2237 }
Note:
See TracChangeset
for help on using the changeset viewer.