aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJohannes Schickel2007-05-27 11:40:03 +0000
committerJohannes Schickel2007-05-27 11:40:03 +0000
commit86104e0bf0b76c06160eb299989262d0e9619c1c (patch)
treea9a96eb21a9004b2e200471009ca4060648b8fd1 /common
parent7d8619350f70f6ca82970b8a12ae0d35c0dacca2 (diff)
downloadscummvm-rg350-86104e0bf0b76c06160eb299989262d0e9619c1c.tar.gz
scummvm-rg350-86104e0bf0b76c06160eb299989262d0e9619c1c.tar.bz2
scummvm-rg350-86104e0bf0b76c06160eb299989262d0e9619c1c.zip
Reverted r26922.
svn-id: r26967
Diffstat (limited to 'common')
-rw-r--r--common/config-manager.cpp2
-rw-r--r--common/singleton.h13
2 files changed, 12 insertions, 3 deletions
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 41f3c1a7e9..f8426f18d0 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -33,6 +33,8 @@
#include "common/file.h"
#include "common/util.h"
+DECLARE_SINGLETON(Common::ConfigManager);
+
#ifdef __PLAYSTATION2__
#include "backends/platform/ps2/systemps2.h"
#endif
diff --git a/common/singleton.h b/common/singleton.h
index f26324999e..5e72e72230 100644
--- a/common/singleton.h
+++ b/common/singleton.h
@@ -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