Reverted r26922.

svn-id: r26967
This commit is contained in:
Johannes Schickel 2007-05-27 11:40:03 +00:00
parent 7d8619350f
commit 86104e0bf0
8 changed files with 24 additions and 3 deletions

View file

@ -37,6 +37,8 @@ private:
Singleton<T>(const Singleton<T>&);
Singleton<T>& operator= (const Singleton<T>&);
static T* _singleton;
/**
* The default object factory used by the template class Singleton.
* By specialising this template function, one can make a singleton use a
@ -56,13 +58,16 @@ public:
public:
static T& instance() {
// TODO: We aren't thread safe.
// TODO: We aren't thread safe. For now we ignore it since the
// only thing using this singleton template is the config manager,
// and that is first instantiated long before any threads.
// TODO: We don't leak, but the destruction order is nevertheless
// semi-random. If we use multiple singletons, the destruction
// order might become an issue. There are various approaches
// to solve that problem, but for now this is sufficient
static T *instance = T::makeInstance();
return *instance;
if (!_singleton)
_singleton = T::makeInstance();
return *_singleton;
}
protected:
Singleton<T>() { }
@ -75,6 +80,8 @@ protected:
typedef T SingletonBaseType;
};
#define DECLARE_SINGLETON(T) template<> T* Common::Singleton<T>::_singleton=0
} // End of namespace Common
#endif