diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2012-10-31 15:21:04 +0100 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2012-10-31 15:21:04 +0100 |
commit | 3660b5ae8d6bcd134072aae742b5682f40a96573 (patch) | |
tree | 8e29c6f5dd5be3748bd1d3d1e9ba319caba7f611 /audio_ril_interface.c | |
parent | 07f20ab0fd9089a1b5c97a9bcbec1df5979f318e (diff) | |
download | hardware_tinyalsa-audio-3660b5ae8d6bcd134072aae742b5682f40a96573.zip hardware_tinyalsa-audio-3660b5ae8d6bcd134072aae742b5682f40a96573.tar.gz hardware_tinyalsa-audio-3660b5ae8d6bcd134072aae742b5682f40a96573.tar.bz2 |
Use mutexes to make audio thread-proof
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'audio_ril_interface.c')
-rw-r--r-- | audio_ril_interface.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/audio_ril_interface.c b/audio_ril_interface.c index d3a8658..0b4383d 100644 --- a/audio_ril_interface.c +++ b/audio_ril_interface.c @@ -42,16 +42,25 @@ int audio_ril_interface_set_mic_mute(struct tinyalsa_audio_ril_interface *ril_in LOGD("%s(%d)", __func__, state); + pthread_mutex_lock(&ril_interface->lock); + if(ril_interface->interface->mic_mute == NULL) - return -1; + goto error; rc = ril_interface->interface->mic_mute(ril_interface->interface->pdata, (int) state); if(rc < 0) { LOGE("Failed to set RIL interface mic mute"); - return -1; + goto error; } + pthread_mutex_unlock(&ril_interface->lock); + return 0; + +error: + pthread_mutex_unlock(&ril_interface->lock); + + return -1; } int audio_ril_interface_set_voice_volume(struct tinyalsa_audio_ril_interface *ril_interface, @@ -64,39 +73,57 @@ int audio_ril_interface_set_voice_volume(struct tinyalsa_audio_ril_interface *ri LOGD("%s(%d, %f)", __func__, device, volume); + pthread_mutex_lock(&ril_interface->lock); + if(ril_interface->interface->voice_volume == NULL) - return -1; + goto error; rc = ril_interface->interface->voice_volume(ril_interface->interface->pdata, device, volume); if(rc < 0) { LOGE("Failed to set RIL interface voice volume"); - return -1; + goto error; } + pthread_mutex_unlock(&ril_interface->lock); + return 0; + +error: + pthread_mutex_unlock(&ril_interface->lock); + + return -1; } int audio_ril_interface_set_route(struct tinyalsa_audio_ril_interface *ril_interface, audio_devices_t device) { int rc; + LOGD("%s(%d)", __func__, device); + if(ril_interface == NULL) return -1; - LOGD("%s(%d)", __func__, device); + pthread_mutex_lock(&ril_interface->lock); ril_interface->device_current = device; if(ril_interface->interface->route == NULL) - return -1; + goto error; rc = ril_interface->interface->route(ril_interface->interface->pdata, device); if(rc < 0) { LOGE("Failed to set RIL interface route"); - return -1; + goto error; } + pthread_mutex_unlock(&ril_interface->lock); + return 0; + +error: + pthread_mutex_unlock(&ril_interface->lock); + + return -1; } /* |