medfall

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

commit c2da1538608d10fd0c021be4d9ef8f81ce4fa60b
parent 5954660545f64bbc042f2842e5635e2e70e050b3
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Feb  7 20:19:38 +0200

Clean shutdown in Linux audio output

Diffstat:
linux_audio_output.cc | 6++++--
linux_audio_output.h | 2++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/linux_audio_output.cc b/linux_audio_output.cc @@ -9,6 +9,7 @@ #include "platform_audio_output.h" #include "platform_library.h" #include "platform_thread.h" +#include "platform_atomic.h" // copied from alsa headers static int ( *_snd_lib_error_set_handler )( snd_lib_error_handler_t handler ) = NULL; @@ -92,7 +93,7 @@ static void audio_output_write( snd_pcm_t * pcm, s16 * samples, s32 num_samples static THREAD( audio_output_thread ) { AudioOutputDevice * device = ( AudioOutputDevice * ) data; - for( ;; ) { + while( load_acquire( &device->shutting_down ) == 0 ) { s16 samples[ 1024 ]; device->callback( samples, ARRAY_COUNT( samples ) ); audio_output_write( device->pcm, samples, ARRAY_COUNT( samples ) ); @@ -120,11 +121,12 @@ void audio_output_open( AudioOutputDevice * device, AudioOutputCallback callback } 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 ); + store_release( &device->shutting_down, 1 ); thread_join( &device->thread ); int err = _snd_pcm_close( device->pcm ); diff --git a/linux_audio_output.h b/linux_audio_output.h @@ -3,9 +3,11 @@ #include <alsa/asoundlib.h> #include "platform_thread.h" +#include "platform_atomic.h" struct AudioOutputDevice { snd_pcm_t * pcm; Thread thread; AudioOutputCallback * callback; + atomic_u32 shutting_down; };