# HG changeset patch # User Chris Cannam # Date 1268405624 0 # Node ID 43b0bfd07bd3284bf50991d0333b1ff5babf37bd # Parent 58c82e10ef0054d7a0b42c8d134ba682e5b1888b * Fix potential static initialiser race (FileFinder vs InteractiveFileFinder instance pointers) diff -r 58c82e10ef00 -r 43b0bfd07bd3 data/fileio/FileFinder.cpp --- 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; - diff -r 58c82e10ef00 -r 43b0bfd07bd3 data/fileio/FileFinder.h --- 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