changeset 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 58c82e10ef00
children f19437971e17
files data/fileio/FileFinder.cpp data/fileio/FileFinder.h
diffstat 2 files changed, 20 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/FileFinder.cpp	Fri Mar 12 13:13:06 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    Sonic Visualiser
-    An audio file viewer and annotation editor.
-    Centre for Digital Music, Queen Mary, University of London.
-    This file copyright 2009 QMUL.
-    
-    This program is free software; you can redistribute it and/or
-    modify it under the terms of the GNU General Public License as
-    published by the Free Software Foundation; either version 2 of the
-    License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#include "FileFinder.h"
-
-FileFinder *
-FileFinder::m_instance = 0;
-
--- 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