Changeset 4c60ef for molecuilder/src/World.cpp
- Timestamp:
- Mar 10, 2010, 5:51:48 PM (16 years ago)
- Children:
- 4fc41a
- Parents:
- 025ca2
- File:
-
- 1 edited
-
molecuilder/src/World.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/World.cpp
r025ca2 r4c60ef 16 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 17 17 #include "Actions/ManipulateAtomsProcess.hpp" 18 19 #include "Patterns/Singleton_impl.hpp" 18 20 19 21 using namespace std; … … 170 172 atomId_t id = *(atomIdPool.begin()); 171 173 atomIdPool.erase(id); 174 return id; 172 175 } 173 176 } … … 227 230 228 231 /******************************* Singleton Stuff **************************/ 229 230 // TODO: Hide boost-thread using Autotools stuff when no threads are used231 World* World::theWorld = 0;232 boost::mutex World::worldLock;233 232 234 233 World::World() : … … 260 259 } 261 260 262 World* World::get(){ 263 // boost supports RAII-Style locking, so we don't need to unlock 264 boost::mutex::scoped_lock guard(worldLock); 265 if(!theWorld) { 266 theWorld = new World(); 267 } 268 return theWorld; 269 } 270 271 void World::destroy(){ 272 // boost supports RAII-Style locking, so we don't need to unlock 273 boost::mutex::scoped_lock guard(worldLock); 274 delete theWorld; 275 theWorld = 0; 276 } 277 278 World* World::reset(){ 279 World* oldWorld = 0; 280 { 281 // boost supports RAII-Style locking, so we don't need to unlock 282 boost::mutex::scoped_lock guard(worldLock); 283 284 oldWorld = theWorld; 285 theWorld = new World(); 286 // oldworld does not need protection any more, 287 // since we should have the only reference 288 289 // worldLock handles access to the pointer, 290 // not to the object 291 } // scope-end releases the lock 292 293 // we have to let all the observers know that the 294 // oldWorld was destroyed. oldWorld calls subjectKilled 295 // upon destruction. Every Observer getting that signal 296 // should see that it gets the updated new world 297 delete oldWorld; 298 return theWorld; 299 } 261 // Explicit instantiation of the singleton mechanism at this point 262 263 CONSTRUCT_SINGLETON(World) 300 264 301 265 /******************************* deprecated Legacy Stuff ***********************/
Note:
See TracChangeset
for help on using the changeset viewer.
