Changeset c6a59b for src/CodePatterns
- Timestamp:
- May 5, 2016, 1:06:20 PM (9 years ago)
- Children:
- c1e104
- Parents:
- 039e15
- git-author:
- Frederik Heber <heber@…> (05/05/16 09:20:08)
- git-committer:
- Frederik Heber <heber@…> (05/05/16 13:06:20)
- Location:
- src/CodePatterns
- Files:
-
- 2 edited
-
Singleton.hpp (modified) (3 diffs)
-
Singleton_impl.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodePatterns/Singleton.hpp
r039e15 rc6a59b 17 17 18 18 #include "CodePatterns/Assert.hpp" 19 #include "CodePatterns/AtomicInstance.hpp" 19 20 20 21 /** … … 145 146 * when only the Singleton pattern is friend with the class 146 147 * 147 * All methods have similar sema tics to auto_ptr148 * All methods have similar semantics to auto_ptr 148 149 */ 149 150 class ptr_t { … … 235 236 236 237 /** 238 * returns the instance of this Singleton as a reference inside a mutex-locked 239 * unique ptr. 240 * 241 * If no Singleton exists at this point and we are allowed to create one 242 * a new one is created and stored inside the singleton. If the mutex is locked, 243 * the function will wait until the mutex is released. This can be used to 244 * ensure atomic access to the static instance. 245 */ 246 static AtomicInstance<T> getLockedInstance(); 247 248 /** 237 249 * returns the instance of this singleton as a pointer 238 250 * -
src/CodePatterns/Singleton_impl.hpp
r039e15 rc6a59b 45 45 } 46 46 return *theInstance; 47 } 48 49 template <class T,bool _may_create> 50 AtomicInstance<T> Singleton<T,_may_create>::getLockedInstance(){ 51 // boost supports RAII-Style locking, so we don't need to unlock 52 boost::recursive_mutex::scoped_lock guard(instanceLock); 53 if(!theInstance.get()) { 54 theInstance.reset(creator::make()); 55 } 56 T *ptr = theInstance.get(); 57 return AtomicInstance<T>(ptr); 47 58 } 48 59 … … 120 131 template name& Singleton< name , name::may_create >::getInstance(); \ 121 132 template const name& Singleton< name , name::may_create >::getConstInstance(); \ 133 template AtomicInstance<name> Singleton< name , name::may_create >::getLockedInstance(); \ 122 134 template name* Singleton< name , name::may_create >::getPointer(); \ 123 135 template const name* Singleton< name , name::may_create >::getConstPointer(); \
Note:
See TracChangeset
for help on using the changeset viewer.
