[Scummvm-cvs-logs] CVS: scummvm/common singleton.h,1.2,1.3

Max Horn fingolfin at users.sourceforge.net
Tue Dec 9 16:13:02 CET 2003


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv23190

Modified Files:
	singleton.h 
Log Message:
slightly altered singleton implemention, might help MSVC6, or might screw it even more :-)

Index: singleton.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/singleton.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- singleton.h	2 Nov 2003 02:18:13 -0000	1.2
+++ singleton.h	10 Dec 2003 00:12:20 -0000	1.3
@@ -31,6 +31,12 @@
 template <class T>
 class Singleton
 {
+private:
+	Singleton<T>(const Singleton<T>&);
+	Singleton<T>& operator= (const Singleton<T>&);
+	
+	static T* _singleton;
+
 public:
 	static T& instance() {
 		// TODO: We aren't thread safe. For now we ignore it since the
@@ -40,17 +46,17 @@
 		// 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 singleton;
-		return singleton;
+		if (!_singleton)
+			_singleton = new T;
+		return *_singleton;
 	}
 protected:
 	Singleton<T>()		{ }
 	~Singleton<T>()		{ }
-
-private:
-	Singleton<T>(const Singleton<T>&);
-	Singleton<T>& operator= (const Singleton<T>&);
 }; 
+
+template <class T>
+T* Singleton<T>::_singleton=0;
 
 }	// End of namespace Common
 





More information about the Scummvm-git-logs mailing list