From 12a47782cb0ae147a396b6bcbbe7909edd8a47be Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 19 Apr 2001 13:53:39 +0000 Subject: [PATCH] Added ctl_elem_lock and unlock code... --- src/control/control.c | 24 ++++++++++++++++++++++++ src/control/control_hw.c | 18 ++++++++++++++++++ src/control/control_local.h | 2 ++ src/control/control_shm.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/src/control/control.c b/src/control/control.c index 3042ae26..a07f1ca6 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -229,6 +229,30 @@ int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control) return ctl->ops->element_write(ctl, control); } +/** + * \brief Lock CTL element + * \param ctl CTL handle + * \param control CTL element id pointer + * \return 0 on success otherwise a negative error code + */ +int snd_ctl_elem_lock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id) +{ + assert(ctl && id); + return ctl->ops->element_lock(ctl, id); +} + +/** + * \brief Unlock CTL element + * \param ctl CTL handle + * \param control CTL element id pointer + * \return 0 on success otherwise a negative error code + */ +int snd_ctl_elem_unlock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id) +{ + assert(ctl && id); + return ctl->ops->element_unlock(ctl, id); +} + /** * \brief Get next hardware dependent device number * \param ctl CTL handle diff --git a/src/control/control_hw.c b/src/control/control_hw.c index d2d3bed7..51966db7 100644 --- a/src/control/control_hw.c +++ b/src/control/control_hw.c @@ -163,6 +163,22 @@ static int snd_ctl_hw_elem_write(snd_ctl_t *handle, snd_ctl_elem_value_t *contro return 0; } +static int snd_ctl_hw_elem_lock(snd_ctl_t *handle, snd_ctl_elem_id_t *id) +{ + snd_ctl_hw_t *hw = handle->private_data; + if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_LOCK, id) < 0) + return -errno; + return 0; +} + +static int snd_ctl_hw_elem_unlock(snd_ctl_t *handle, snd_ctl_elem_id_t *id) +{ + snd_ctl_hw_t *hw = handle->private_data; + if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_UNLOCK, id) < 0) + return -errno; + return 0; +} + static int snd_ctl_hw_hwdep_next_device(snd_ctl_t *handle, int * device) { snd_ctl_hw_t *hw = handle->private_data; @@ -255,6 +271,8 @@ snd_ctl_ops_t snd_ctl_hw_ops = { element_info: snd_ctl_hw_elem_info, element_read: snd_ctl_hw_elem_read, element_write: snd_ctl_hw_elem_write, + element_lock: snd_ctl_hw_elem_lock, + element_unlock: snd_ctl_hw_elem_unlock, hwdep_next_device: snd_ctl_hw_hwdep_next_device, hwdep_info: snd_ctl_hw_hwdep_info, pcm_next_device: snd_ctl_hw_pcm_next_device, diff --git a/src/control/control_local.h b/src/control/control_local.h index 0246d5a3..69ae2faa 100644 --- a/src/control/control_local.h +++ b/src/control/control_local.h @@ -33,6 +33,8 @@ typedef struct _snd_ctl_ops { int (*element_info)(snd_ctl_t *handle, snd_ctl_elem_info_t *info); int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_value_t *control); int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_value_t *control); + int (*element_lock)(snd_ctl_t *handle, snd_ctl_elem_id_t *lock); + int (*element_unlock)(snd_ctl_t *handle, snd_ctl_elem_id_t *unlock); int (*hwdep_next_device)(snd_ctl_t *handle, int *device); int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info); int (*pcm_next_device)(snd_ctl_t *handle, int *device); diff --git a/src/control/control_shm.c b/src/control/control_shm.c index f525f178..cbc5aef9 100644 --- a/src/control/control_shm.c +++ b/src/control/control_shm.c @@ -207,6 +207,34 @@ static int snd_ctl_shm_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control) return err; } +static int snd_ctl_shm_elem_lock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id) +{ + snd_ctl_shm_t *shm = ctl->private_data; + volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl; + int err; + ctrl->u.element_lock = *id; + ctrl->cmd = SNDRV_CTL_IOCTL_ELEM_LOCK; + err = snd_ctl_shm_action(ctl); + if (err < 0) + return err; + *id = ctrl->u.element_lock; + return err; +} + +static int snd_ctl_shm_elem_unlock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id) +{ + snd_ctl_shm_t *shm = ctl->private_data; + volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl; + int err; + ctrl->u.element_unlock = *id; + ctrl->cmd = SNDRV_CTL_IOCTL_ELEM_UNLOCK; + err = snd_ctl_shm_action(ctl); + if (err < 0) + return err; + *id = ctrl->u.element_unlock; + return err; +} + static int snd_ctl_shm_hwdep_next_device(snd_ctl_t *ctl, int * device) { snd_ctl_shm_t *shm = ctl->private_data; @@ -362,6 +390,8 @@ snd_ctl_ops_t snd_ctl_shm_ops = { element_info: snd_ctl_shm_elem_info, element_read: snd_ctl_shm_elem_read, element_write: snd_ctl_shm_elem_write, + element_lock: snd_ctl_shm_elem_lock, + element_unlock: snd_ctl_shm_elem_unlock, hwdep_next_device: snd_ctl_shm_hwdep_next_device, hwdep_info: snd_ctl_shm_hwdep_info, pcm_next_device: snd_ctl_shm_pcm_next_device, -- 2.47.1