From: Daniel Caujolle-B. <f1...@us...> - 2001-12-24 13:02:55
|
Update of /cvsroot/xine/xine-lib/src/audio_out In directory usw-pr-cvs1:/tmp/cvs-serv11649 Modified Files: Tag: stable audio_alsa_out.c Log Message: Close sound mixer on exit (patch from Chris Rankin <ran...@ya...>) Index: audio_alsa_out.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/audio_out/audio_alsa_out.c,v retrieving revision 1.42.2.1 retrieving revision 1.42.2.2 diff -u -r1.42.2.1 -r1.42.2.2 --- audio_alsa_out.c 2001/12/21 21:53:30 1.42.2.1 +++ audio_alsa_out.c 2001/12/24 13:02:53 1.42.2.2 @@ -107,8 +107,6 @@ static void *ao_alsa_handle_event_thread(void *data) { alsa_driver_t *this = (alsa_driver_t *) data; - pthread_detach(pthread_self()); - do { snd_mixer_wait(this->mixer.handle, -1); snd_mixer_handle_events(this->mixer.handle); @@ -155,6 +153,7 @@ snd_pcm_sw_params_t *swparams; snd_pcm_sframes_t buffer_size; snd_pcm_sframes_t period_size,tmp; + /* snd_aes_iec958_t spdif; snd_ctl_elem_value_t *ctl; snd_ctl_t *ctl_handle; @@ -162,6 +161,7 @@ char ctl_name[12]; int ctl_card; int err, step; + */ // int open_mode=1; //NONBLOCK int open_mode=0; //BLOCK @@ -488,6 +488,7 @@ static void ao_alsa_exit(ao_driver_t *this_gen) { alsa_driver_t *this = (alsa_driver_t *) this_gen; + void *p; config_values_t *config = this->config; @@ -498,7 +499,19 @@ this->mixer.min, this->mixer.max))) /2)); config->save(config); - pthread_cancel(this->mixer.thread); + /* + * Destroy the mixer thread and cleanup the mixer, so that + * any child processes (such as xscreensaver) cannot inherit + * the mixer's handle and keep it open. + * By rejoining the mixer thread, we remove a race condition + * between closing the handle and spawning the child process + * (i.e. xscreensaver). + */ + if(this->mixer.handle) { + pthread_cancel(this->mixer.thread); + pthread_join(this->mixer.thread, &p); + snd_mixer_close(this->mixer.handle); + } if (this->audio_fd) snd_pcm_close(this->audio_fd); free (this); |