control, pcm: implement snd_ctl_abort() and snd_pcm_abort() functions

Upon an interrupt, it is necessary to abort the wait loops with the EINTR
error code. Introduce snd_*_abort() functions to handle this case.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2013-04-08 13:28:03 +02:00
parent 730c833dd8
commit e23fb2c4de
7 changed files with 17 additions and 4 deletions

View file

@ -103,7 +103,7 @@ int snd_ctl_close(snd_ctl_t *ctl)
/**
* \brief set nonblock mode
* \param ctl CTL handle
* \param nonblock 0 = block, 1 = nonblock mode
* \param nonblock 0 = block, 1 = nonblock mode, 2 = abort
* \return 0 on success otherwise a negative error code
*/
int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)

View file

@ -98,3 +98,5 @@ int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode);
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname, const char *sname, int mode);
int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid);
#define CTLINABORT(x) ((x)->nonblock == 2)

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)
if (errno == EINTR && !CTLINABORT(hctl->ctl))
continue;
return -errno;
}

View file

@ -716,7 +716,7 @@ int snd_pcm_close(snd_pcm_t *pcm)
/**
* \brief set nonblock mode
* \param pcm PCM handle
* \param nonblock 0 = block, 1 = nonblock mode
* \param nonblock 0 = block, 1 = nonblock mode, 2 = abort
* \return 0 on success otherwise a negative error code
*/
int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock)
@ -725,6 +725,10 @@ int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock)
assert(pcm);
if ((err = pcm->ops->nonblock(pcm->op_arg, nonblock)) < 0)
return err;
if (nonblock == 2) {
pcm->mode |= SND_PCM_ABORT;
return 0;
}
if (nonblock)
pcm->mode |= SND_PCM_NONBLOCK;
else {
@ -2401,7 +2405,7 @@ int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout)
do {
err_poll = poll(pfd, npfds, timeout);
if (err_poll < 0) {
if (errno == EINTR)
if (errno == EINTR && !PCMINABORT(pcm))
continue;
return -errno;
}

View file

@ -1006,3 +1006,5 @@ static inline void sw_set_period_event(snd_pcm_sw_params_t *params, int val)
{
params->reserved[sizeof(params->reserved) / sizeof(params->reserved[0]) - 1] = val;
}
#define PCMINABORT(pcm) (((pcm)->mode & SND_PCM_ABORT) != 0)