pcm: add SND_CTL_EINTR open mode

Add possibility to return -EINTR instead waiting for the event. The
applications may want to handle -EINTR condition themselves.

BugLink: https://github.com/alsa-project/alsa-lib/issues/228
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2023-05-03 11:48:35 +02:00
parent d6d5982d3a
commit 507d906abb
8 changed files with 13 additions and 8 deletions

View file

@ -356,6 +356,9 @@ typedef enum _snd_ctl_type {
/** Read only (flag for open mode) \hideinitializer */
#define SND_CTL_READONLY 0x0004
/** Return EINTR instead blocking (flag for open mode) \hideinitializer */
#define SND_CTL_EINTR 0x0080
/** CTL handle */
typedef struct _snd_ctl snd_ctl_t;

View file

@ -265,13 +265,14 @@ int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)
}
#ifndef DOC_HIDDEN
int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name)
int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name, int mode)
{
snd_ctl_t *ctl;
ctl = calloc(1, sizeof(*ctl));
if (!ctl)
return -ENOMEM;
ctl->type = type;
ctl->mode = mode;
if (name)
ctl->name = strdup(name);
INIT_LIST_HEAD(&ctl->async_handlers);

View file

@ -716,7 +716,7 @@ int snd_ctl_ext_create(snd_ctl_ext_t *ext, const char *name, int mode)
return -ENXIO;
}
err = snd_ctl_new(&ctl, SND_CTL_TYPE_EXT, name);
err = snd_ctl_new(&ctl, SND_CTL_TYPE_EXT, name, mode);
if (err < 0)
return err;

View file

@ -444,7 +444,7 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode)
hw->fd = fd;
hw->protocol = ver;
err = snd_ctl_new(&ctl, SND_CTL_TYPE_HW, name);
err = snd_ctl_new(&ctl, SND_CTL_TYPE_HW, name, mode);
if (err < 0) {
close(fd);
free(hw);

View file

@ -62,6 +62,7 @@ struct _snd_ctl {
snd_ctl_type_t type;
const snd_ctl_ops_t *ops;
void *private_data;
int mode;
int nonblock;
int poll_fd;
struct list_head async_handlers;
@ -93,7 +94,7 @@ struct _snd_hctl {
/* make local functions really local */
#define snd_ctl_new snd1_ctl_new
int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name);
int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name, int mode);
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
#define _snd_ctl_async_descriptor _snd_ctl_poll_descriptor
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode);

View file

@ -1148,7 +1148,7 @@ static int parse_map(snd_ctl_remap_t *priv, snd_config_t *conf)
* changed in future.
*/
int snd_ctl_remap_open(snd_ctl_t **handlep, const char *name, snd_config_t *remap,
snd_config_t *map, snd_ctl_t *child, int mode ATTRIBUTE_UNUSED)
snd_config_t *map, snd_ctl_t *child, int mode)
{
snd_ctl_remap_t *priv;
snd_ctl_t *ctl;
@ -1195,7 +1195,7 @@ int snd_ctl_remap_open(snd_ctl_t **handlep, const char *name, snd_config_t *rema
priv->numid_remap_active = priv->map_items > 0;
priv->child = child;
err = snd_ctl_new(&ctl, SND_CTL_TYPE_REMAP, name);
err = snd_ctl_new(&ctl, SND_CTL_TYPE_REMAP, name, mode);
if (err < 0) {
result = err;
goto _err;

View file

@ -502,7 +502,7 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname
shm->socket = sock;
shm->ctrl = ctrl;
err = snd_ctl_new(&ctl, SND_CTL_TYPE_SHM, name);
err = snd_ctl_new(&ctl, SND_CTL_TYPE_SHM, name, mode);
if (err < 0) {
result = err;
goto _err;

View file

@ -696,7 +696,7 @@ int snd_hctl_wait(snd_hctl_t *hctl, int timeout)
pollio = 0;
err_poll = poll(pfd, npfds, timeout);
if (err_poll < 0) {
if (errno == EINTR && !CTLINABORT(hctl->ctl))
if (errno == EINTR && !CTLINABORT(hctl->ctl) && !(hctl->ctl->mode & SND_CTL_EINTR))
continue;
return -errno;
}