Skip to content

Commit

Permalink
lengthen some mutex timeouts to allow valgrind to work okay on a Pi 3…
Browse files Browse the repository at this point in the history
…B. Make operations that open the mixer uncancellable until it's closed again to stop a few small memory leaks when a player is cancelled.
  • Loading branch information
mikebrady committed Feb 1, 2019
1 parent 02bc269 commit bfc7b9b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions audio_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,24 +1051,26 @@ static void deinit(void) {

int set_mute_state() {
int response = 1; // some problem expected, e.g. no mixer or not allowed to use it or disconnected
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
pthread_cleanup_debug_mutex_lock(&alsa_mixer_mutex, 10000, 0);
if ((alsa_backend_state != abm_disconnected) && (config.alsa_use_hardware_mute == 1) &&
(open_mixer() == 1)) {
response = 0; // okay if actually using the mute facility
debug(1, "set_mute_state");
debug(2, "alsa: actually set_mute_state");
int mute = 0;
if ((mute_requested_externally != 0) || (mute_requested_internally != 0))
mute = 1;
if (mute == 1) {
debug(1, "Hardware mute switched on");
debug(2, "alsa: hardware mute switched on");
if (snd_mixer_selem_has_playback_switch(alsa_mix_elem))
snd_mixer_selem_set_playback_switch_all(alsa_mix_elem, 0);
else {
volume_based_mute_is_active = 1;
do_snd_mixer_selem_set_playback_dB_all(alsa_mix_elem, alsa_mix_mute);
}
} else {
debug(1, "Hardware mute switched off");
debug(2, "alsa: hardware mute switched off");
if (snd_mixer_selem_has_playback_switch(alsa_mix_elem))
snd_mixer_selem_set_playback_switch_all(alsa_mix_elem, 1);
else {
Expand All @@ -1080,6 +1082,7 @@ int set_mute_state() {
}
debug_mutex_unlock(&alsa_mixer_mutex, 3); // release the mutex
pthread_cleanup_pop(0); // release the mutex
pthread_setcancelstate(oldState, NULL);
return response;
}

Expand Down Expand Up @@ -1374,7 +1377,7 @@ int play(void *buf, int samples) {
// debug(3,"audio_alsa play called.");
int ret = 0;

pthread_cleanup_debug_mutex_lock(&alsa_mutex, 10000, 1);
pthread_cleanup_debug_mutex_lock(&alsa_mutex, 50000, 1);

if (alsa_backend_state == abm_disconnected) {
ret = do_open();
Expand Down Expand Up @@ -1520,7 +1523,7 @@ void *alsa_buffer_monitor_thread_code(__attribute__((unused)) void *arg) {
do_alsa_device_init_if_needed();
}
int sleep_time_ms = (int)(config.audio_backend_silence_scan_interval * 1000);
pthread_cleanup_debug_mutex_lock(&alsa_mutex, 20000, 1);
pthread_cleanup_debug_mutex_lock(&alsa_mutex, 200000, 1);
// check possible state transitions here
if ((alsa_backend_state == abm_disconnected) && (config.keep_dac_busy != 0)) {
// open the dac and move to abm_connected mode
Expand Down

0 comments on commit bfc7b9b

Please sign in to comment.