[alsa-devel] [PATCH] alsa-lib: Remove usleep usage
Rosen Penev
rosenp at gmail.com
Mon Sep 2 03:32:40 CEST 2019
usleep was deprecated by POSIX 2008 and is unavailable without deprecated
APIs enabled in uClibc-ng.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
src/pcm/pcm_shm.c | 3 ++-
src/ucm/main.c | 3 ++-
test/mixtest.c | 2 +-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/pcm/pcm_shm.c b/src/pcm/pcm_shm.c
index 26a27a57..30a77cd4 100644
--- a/src/pcm/pcm_shm.c
+++ b/src/pcm/pcm_shm.c
@@ -485,12 +485,13 @@ static int snd_pcm_shm_drain(snd_pcm_t *pcm)
snd_pcm_shm_t *shm = pcm->private_data;
volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;
int err;
+ struct timespec req = { 0, 10 * 1000 * 1000 };
do {
ctrl->cmd = SNDRV_PCM_IOCTL_DRAIN;
err = snd_pcm_shm_action(pcm);
if (err != -EAGAIN)
break;
- usleep(10000);
+ nanosleep(&req, NULL);
} while (1);
if (err < 0)
return err;
diff --git a/src/ucm/main.c b/src/ucm/main.c
index 99b1cd08..0e5236cb 100644
--- a/src/ucm/main.c
+++ b/src/ucm/main.c
@@ -359,6 +359,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr,
{
struct list_head *pos;
struct sequence_element *s;
+ struct timespec sleep = { 0, s->data.sleep * 1000 };
char *cdev = NULL;
snd_ctl_t *ctl = NULL;
int err = 0;
@@ -440,7 +441,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr,
}
break;
case SEQUENCE_ELEMENT_TYPE_SLEEP:
- usleep(s->data.sleep);
+ nanosleep(&sleep, NULL);
break;
case SEQUENCE_ELEMENT_TYPE_EXEC:
err = system(s->data.exec);
diff --git a/test/mixtest.c b/test/mixtest.c
index 57ca5d53..f0940344 100644
--- a/test/mixtest.c
+++ b/test/mixtest.c
@@ -77,7 +77,7 @@ static double detect_cpu_clock()
rdtscll(tsc_begin);
clock_gettime(CLOCK_MONOTONIC, &tm_begin);
- usleep(1000000);
+ sleep(1);
rdtscll(tsc_end);
clock_gettime(CLOCK_MONOTONIC, &tm_end);
--
2.17.1
More information about the Alsa-devel
mailing list