29 #include <boost/noncopyable.hpp>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/thread.hpp>
32 #include <boost/bind.hpp>
78 static void createMutex(boost::mutex*& destination);
86 destination =
new boost::mutex();
91 static boost::mutex* instanceMutex;
92 static boost::once_flag instanceMutexOnceFlag = BOOST_ONCE_INIT;
93 boost::call_once(instanceMutexOnceFlag,
95 return *instanceMutex;
100 boost::mutex& instanceMutex = getInstanceMutex();
101 boost::mutex::scoped_lock lock(instanceMutex);
103 boost::shared_ptr<T>& instance = getStorage();
106 instance = boost::shared_ptr<T>(
new T());
118 boost::mutex& instanceMutex = getInstanceMutex();
119 boost::mutex::scoped_lock lock(instanceMutex);
121 boost::shared_ptr<T>& instance = getStorage();
130 static boost::shared_ptr<T> instance = boost::shared_ptr<T>();
This template class implements the singleton pattern.
static boost::mutex & getInstanceMutex()
static boost::shared_ptr< T > & getStorage()
static void createMutex(boost::mutex *&destination)
static void killInstance()
This function can be used to make sure the instance is deleted at a particular time.
static T & getInstance()
Retrieve the singleton instance, creating it if necessary.