aboutsummaryrefslogtreecommitdiff
path: root/common/singleton.h
diff options
context:
space:
mode:
authorDavid Corrales2007-05-31 23:44:43 +0000
committerDavid Corrales2007-05-31 23:44:43 +0000
commit0cab5b7791e56b32455748bf20c21f0d6b42f654 (patch)
tree9e6580328542f1db230e019ba77e3db1be8fa50b /common/singleton.h
parent6c69d531d262e14fa02b6e1adb42baaa5c74dbe6 (diff)
parent22c0403e0dfec16badf156afa842c6c37e850263 (diff)
downloadscummvm-rg350-0cab5b7791e56b32455748bf20c21f0d6b42f654.tar.gz
scummvm-rg350-0cab5b7791e56b32455748bf20c21f0d6b42f654.tar.bz2
scummvm-rg350-0cab5b7791e56b32455748bf20c21f0d6b42f654.zip
Merged the fs branch with trunk. r26949:27031
svn-id: r27032
Diffstat (limited to 'common/singleton.h')
-rw-r--r--common/singleton.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/common/singleton.h b/common/singleton.h
index f26324999e..56039afb37 100644
--- a/common/singleton.h
+++ b/common/singleton.h
@@ -1,6 +1,8 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2001 Ludvig Strigeus
- * Copyright (C) 2001-2006 The ScummVM project
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -37,6 +39,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 +60,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 +82,8 @@ protected:
typedef T SingletonBaseType;
};
+#define DECLARE_SINGLETON(T) template<> T* Common::Singleton<T>::_singleton=0
+
} // End of namespace Common
#endif