]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: add SND_CTL_EINTR open mode
authorJaroslav Kysela <perex@perex.cz>
Wed, 3 May 2023 09:48:35 +0000 (11:48 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 3 May 2023 13:59:15 +0000 (15:59 +0200)
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>
include/control.h
src/control/control.c
src/control/control_ext.c
src/control/control_hw.c
src/control/control_local.h
src/control/control_remap.c
src/control/control_shm.c
src/control/hcontrol.c

index e386ecec92f1b458a9bd72717ebf29920f882a12..d0c40d2fa32b2e06eed1ce4f9f24d8165f11da0a 100644 (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;
 
index 91415b512007f5f2e141f22aa8066602635c58db..c4ca74ec5497f7bc470b8da84581bfb86961ff51 100644 (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);
index 515f78822f21502596d983c83aee74798302dde3..0dcc8538aa39d061146ac6bbb6be2827e26f33bd 100644 (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;
 
index 0ed9f6b229236fe073c2ef286508cccd147a5c81..02636910c809c5cc73762da6959e634a3c02fbca 100644 (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);
index 973fa04c145d87e4c605a7929729adba998e5944..b84dc4291c293936ada961a18dbc2df8cdc1b5e5 100644 (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);
index 4914f9607414725356bae312006debee55d7cd49..5bc566087ed5df79c27319cef793da5cb84e726d 100644 (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;
index d7297e6cbf1f689ab882e0d0bdf60221883b4ef0..3d1555ee4362483b9c49d06e83c7041063068ff1 100644 (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;
index 0cac89567c84b52ae85a009582f2bf7dff6fd8f6..18ddc16b4b2a681e0ea90132dd9e52b4d26a3c1f 100644 (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;
                }