Avoid race condition in pause, switch to shared_ptr for simpler semantics.

This commit is contained in:
Christian Speckner 2018-01-28 00:27:25 +01:00
parent 4528b9067a
commit 6b984a8563
9 changed files with 15 additions and 14 deletions

View File

@ -100,7 +100,7 @@ void SoundSDL2::setEnabled(bool state)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL2::open(AudioQueue* audioQueue) void SoundSDL2::open(shared_ptr<AudioQueue> audioQueue)
{ {
myOSystem.logMessage("SoundSDL2::open started ...", 2); myOSystem.logMessage("SoundSDL2::open started ...", 2);
mute(true); mute(true);
@ -141,10 +141,11 @@ void SoundSDL2::close()
{ {
if(!myIsInitializedFlag) return; if(!myIsInitializedFlag) return;
mute(true);
myAudioQueue = 0; myAudioQueue = 0;
myCurrentFragment = 0; myCurrentFragment = 0;
mute(true);
myOSystem.logMessage("SoundSDL2::close", 2); myOSystem.logMessage("SoundSDL2::close", 2);
} }

View File

@ -59,7 +59,7 @@ class SoundSDL2 : public Sound
Initializes the sound device. This must be called before any Initializes the sound device. This must be called before any
calls are made to derived methods. calls are made to derived methods.
*/ */
void open(AudioQueue* audioQueue) override; void open(shared_ptr<AudioQueue> audioQueue) override;
/** /**
Should be called to close the sound device. Once called the sound Should be called to close the sound device. Once called the sound
@ -117,7 +117,7 @@ class SoundSDL2 : public Sound
// Audio specification structure // Audio specification structure
SDL_AudioSpec myHardwareSpec; SDL_AudioSpec myHardwareSpec;
AudioQueue* myAudioQueue; shared_ptr<AudioQueue> myAudioQueue;
Int16* myCurrentFragment; Int16* myCurrentFragment;
uInt32 myTimeIndex; uInt32 myTimeIndex;

View File

@ -183,7 +183,7 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
} }
createAudioQueue(); createAudioQueue();
myTIA->setAudioQueue(myAudioQueue.get()); myTIA->setAudioQueue(myAudioQueue);
bool joyallow4 = myOSystem.settings().getBool("joyallow4"); bool joyallow4 = myOSystem.settings().getBool("joyallow4");
myOSystem.eventHandler().allowAllDirections(joyallow4); myOSystem.eventHandler().allowAllDirections(joyallow4);
@ -580,7 +580,7 @@ void Console::initializeAudio()
// const string& sound = myProperties.get(Cartridge_Sound); // const string& sound = myProperties.get(Cartridge_Sound);
// myOSystem.sound().setChannels(sound == "STEREO" ? 2 : 1); // myOSystem.sound().setChannels(sound == "STEREO" ? 2 : 1);
myOSystem.sound().open(myAudioQueue.get()); myOSystem.sound().open(myAudioQueue);
// Make sure auto-frame calculation is only enabled when necessary // Make sure auto-frame calculation is only enabled when necessary
myTIA->enableAutoFrame(framerate <= 0); myTIA->enableAutoFrame(framerate <= 0);
@ -754,7 +754,7 @@ void Console::createAudioQueue()
throw runtime_error("invalid console timing"); throw runtime_error("invalid console timing");
} }
myAudioQueue = make_unique<AudioQueue>( myAudioQueue = make_shared<AudioQueue>(
fragmentSize, fragmentSize,
AUDIO_QUEUE_CAPACITY_FRAGMENTS, AUDIO_QUEUE_CAPACITY_FRAGMENTS,
myProperties.get(Cartridge_Sound) == "STEREO", myProperties.get(Cartridge_Sound) == "STEREO",

View File

@ -388,7 +388,7 @@ class Console : public Serializable
unique_ptr<AbstractFrameManager> myFrameManager; unique_ptr<AbstractFrameManager> myFrameManager;
// The audio fragment queue that connects TIA and audio driver // The audio fragment queue that connects TIA and audio driver
unique_ptr<AudioQueue> myAudioQueue; shared_ptr<AudioQueue> myAudioQueue;
// Pointer to the Cartridge (the debugger needs it) // Pointer to the Cartridge (the debugger needs it)
unique_ptr<Cartridge> myCart; unique_ptr<Cartridge> myCart;

View File

@ -51,7 +51,7 @@ class Sound
Start the sound system, initializing it if necessary. This must be Start the sound system, initializing it if necessary. This must be
called before any calls are made to derived methods. called before any calls are made to derived methods.
*/ */
virtual void open(AudioQueue* audioQueue) = 0; virtual void open(shared_ptr<AudioQueue> audioQueue) = 0;
/** /**
Should be called to stop the sound system. Once called the sound Should be called to stop the sound system. Once called the sound

View File

@ -53,7 +53,7 @@ void Audio::reset()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::setAudioQueue(AudioQueue* queue) void Audio::setAudioQueue(shared_ptr<AudioQueue> queue)
{ {
myAudioQueue = queue; myAudioQueue = queue;

View File

@ -30,7 +30,7 @@ class Audio
void reset(); void reset();
void setAudioQueue(AudioQueue *queue); void setAudioQueue(shared_ptr<AudioQueue> queue);
void tick(); void tick();
@ -42,7 +42,7 @@ class Audio
void phase1(); void phase1();
private: private:
AudioQueue* myAudioQueue; shared_ptr<AudioQueue> myAudioQueue;
uInt8 myCounter; uInt8 myCounter;

View File

@ -117,7 +117,7 @@ void TIA::setFrameManager(AbstractFrameManager *frameManager)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIA::setAudioQueue(AudioQueue* queue) void TIA::setAudioQueue(shared_ptr<AudioQueue> queue)
{ {
myAudio.setAudioQueue(queue); myAudio.setAudioQueue(queue);
} }

View File

@ -114,7 +114,7 @@ class TIA : public Device
Set the audio queue. This needs to be dynamic as the queue is created after Set the audio queue. This needs to be dynamic as the queue is created after
the timing has been determined. the timing has been determined.
*/ */
void setAudioQueue(AudioQueue *audioQueue); void setAudioQueue(shared_ptr<AudioQueue> audioQueue);
/** /**
Clear the configured frame manager and deteach the lifecycle callbacks. Clear the configured frame manager and deteach the lifecycle callbacks.