diff data/fileio/FileFinder.h @ 622:43b0bfd07bd3

* Fix potential static initialiser race (FileFinder vs InteractiveFileFinder instance pointers)
author Chris Cannam
date Fri, 12 Mar 2010 14:53:44 +0000
parents 442e2ff876aa
children 1de00ee53be1
line wrap: on
line diff
--- a/data/fileio/FileFinder.h	Fri Mar 12 13:13:06 2010 +0000
+++ b/data/fileio/FileFinder.h	Fri Mar 12 14:53:44 2010 +0000
@@ -37,11 +37,28 @@
 
     virtual QString find(FileType type, QString location, QString lastKnownLocation = "") = 0;
 
-    static FileFinder *getInstance() { return m_instance; }
+    static FileFinder *getInstance() {
+        FFContainer *container = FFContainer::getInstance();
+        return container->getFileFinder();
+    }
 
 protected:
-    static void registerFileFinder(FileFinder *ff) { m_instance = ff; }
-    static FileFinder *m_instance;
+    class FFContainer {
+    public:
+        static FFContainer *getInstance() {
+            static FFContainer instance;
+            return &instance;
+        }
+        void setFileFinder(FileFinder *ff) { m_ff = ff; }
+        FileFinder *getFileFinder() const { return m_ff; }
+    private:
+        FileFinder *m_ff;
+    };
+
+    static void registerFileFinder(FileFinder *ff) {
+        FFContainer *container = FFContainer::getInstance();
+        container->setFileFinder(ff);
+    }
 };
 
 #endif