medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit f0bd89907779f3f4456d59cf70d8214cab3044f8
parent 75e7f35012b66e31278e041fc0ee6fd4511a74a7
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Feb  7 20:23:42 +0200

Stop the mixer thread in audio_output_close on Windows

Diffstat:
win32_audio_output.cc | 9++++++---
win32_audio_output.h | 2++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/win32_audio_output.cc b/win32_audio_output.cc @@ -10,6 +10,7 @@ #include "platform_audio_output.h" #include "platform_library.h" #include "platform_thread.h" +#include "platform_atomic.h" struct XAudioCallbacks : public IXAudio2VoiceCallback { void __stdcall OnBufferEnd( void * data ) { @@ -69,7 +70,8 @@ static THREAD( audio_output_thread ) { // double buffering s16 buffers[ 2 ][ 512 ]; u32 buffer_idx = 0; - for( ;; ) { + + while( load_acquire( &device->shutting_down ) == 0 ) { for( ;; ) { XAUDIO2_VOICE_STATE state; device->voice->GetState( &state ); @@ -120,12 +122,13 @@ void audio_output_open( AudioOutputDevice * device, AudioOutputCallback callback device->voice->Start( 0 ); device->callback = callback; + store_release( &device->shutting_down, 0 ); thread_init( &device->thread, audio_output_thread, device ); } void audio_output_close( AudioOutputDevice * device ) { - //thread_cancel( &device->thread ); - //thread_join( &device->thread ); + store_release( &device->shutting_down, 1 ); + thread_join( &device->thread ); device->voice->Stop( 0 ); device->voice->FlushSourceBuffers(); diff --git a/win32_audio_output.h b/win32_audio_output.h @@ -2,6 +2,7 @@ #include "intrinsics.h" #include "platform_thread.h" +#include "platform_atomic.h" #include <windows.h> #include <xaudio2.h> @@ -11,4 +12,5 @@ struct AudioOutputDevice { HANDLE event; Thread thread; AudioOutputCallback * callback; + atomic_u32 shutting_down; };