diff options
Diffstat (limited to 'osframework/source/SexyAppFramework/SoundDriverFactory.cpp')
-rw-r--r-- | osframework/source/SexyAppFramework/SoundDriverFactory.cpp | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/osframework/source/SexyAppFramework/SoundDriverFactory.cpp b/osframework/source/SexyAppFramework/SoundDriverFactory.cpp index 88888ab..438fc5a 100644 --- a/osframework/source/SexyAppFramework/SoundDriverFactory.cpp +++ b/osframework/source/SexyAppFramework/SoundDriverFactory.cpp @@ -26,13 +26,55 @@ SoundDriverFactory::~SoundDriverFactory () { } -SoundDriverFactory* SoundDriverFactory::GetSoundDriverFactory () +namespace Sexy { + +class StaticSoundDriverFactory { - static SoundDriverFactory * theSoundDriverFactory; +public: + struct StaticData { + SoundDriverFactory* mFactory; + bool mDone; + }; + + StaticSoundDriverFactory(StaticData* data) + { + mData = data; + } + + SoundDriverFactory* Get(StaticData* data) + { + if (data->mDone) + return 0; + + if (data->mFactory) + return data->mFactory; + + data->mFactory = new SoundDriverFactory; + return data->mFactory; + } + + ~StaticSoundDriverFactory() + { + if (!mData) + return; + + mData->mDone = true; + if (mData->mFactory) + delete mData->mFactory; + } + +private: + StaticData* mData; +}; + +static StaticSoundDriverFactory::StaticData aData; +static StaticSoundDriverFactory soundDriverFactory(&aData); - if (!theSoundDriverFactory) - theSoundDriverFactory = new SoundDriverFactory (); - return theSoundDriverFactory; +} + +SoundDriverFactory* SoundDriverFactory::GetSoundDriverFactory () +{ + return soundDriverFactory.Get(&aData); } /* This is a hack that preventing gcc from striping drivers out of @@ -52,11 +94,12 @@ SoundDriverGetter SoundDriverGetters []= { GetAudiereSoundDriver, #endif #ifdef SEXY_DIRECT_SOUND_DRIVER - GetDSoundDriver, + GetDSoundDriver, #endif #ifdef SEXY_OPENAL_SOUND_DRIVER - GetOpenALSoundDriver, + GetOpenALSoundDriver, #endif + GetDummySoundDriver, NULL }; |