[alsa-devel] [PATCH] alsa-utils: Remove usleep usage
Rosen Penev
rosenp at gmail.com
Mon Sep 2 03:27:05 CEST 2019
usleep was deprecated in POSIX 2008 and is not available without
deprecated APIs enabled in uClibc-ng.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
alsactl/daemon.c | 3 ++-
alsaloop/pcmjob.c | 3 ++-
amidi/amidi.c | 6 ++++--
bat/bat.c | 5 +++--
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/alsactl/daemon.c b/alsactl/daemon.c
index 1d98caa..3b84cf6 100644
--- a/alsactl/daemon.c
+++ b/alsactl/daemon.c
@@ -348,7 +348,8 @@ static int check_another_instance(const char *pidfile)
if (pid >= 0) {
/* invoke new card rescan */
if (kill(pid, SIGUSR1) >= 0) {
- usleep(1000);
+ struct timespec req = { 0, 1 * 1000 * 1000 };
+ nanosleep(&req, NULL);
pid = read_pid_file(pidfile);
if (pid >= 0)
return 1;
diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c
index 29d1aba..d0347dc 100644
--- a/alsaloop/pcmjob.c
+++ b/alsaloop/pcmjob.c
@@ -662,10 +662,11 @@ static int xrun(struct loopback_handle *lhandle)
static int suspend(struct loopback_handle *lhandle)
{
+ struct timespec req = { 0, 1000};
int err;
while ((err = snd_pcm_resume(lhandle->handle)) == -EAGAIN)
- usleep(1);
+ nanosleep(&req, NULL);
if (err < 0)
return xrun(lhandle);
return 0;
diff --git a/amidi/amidi.c b/amidi/amidi.c
index b6e05e1..3b2953d 100644
--- a/amidi/amidi.c
+++ b/amidi/amidi.c
@@ -254,10 +254,12 @@ static int send_midi_interleaved(void)
snd_rawmidi_status(output, st);
do {
/* 320 µs per byte as noted in Page 1 of MIDI spec */
- usleep((buffer_size - snd_rawmidi_status_get_avail(st)) * 320);
+ struct timespec req = { 0, (buffer_size - snd_rawmidi_status_get_avail(st)) * 320 * 1000};
+ nanosleep(&req, NULL);
snd_rawmidi_status(output, st);
} while(snd_rawmidi_status_get_avail(st) < buffer_size);
- usleep(sysex_interval * 1000);
+ struct timespec sysex = { 0, sysex_interval * 1000 * 1000};
+ nanosleep(&sysex, NULL);
}
/* find end of SysEx */
diff --git a/bat/bat.c b/bat/bat.c
index 8645770..27e7a34 100644
--- a/bat/bat.c
+++ b/bat/bat.c
@@ -176,6 +176,7 @@ static void test_loopback(struct bat *bat)
pthread_t capture_id, playback_id;
int err;
int *thread_result_capture, *thread_result_playback;
+ struct timespec capture_delay = { 0, CAPTURE_DELAY * 1000 * 1000 };
/* start playback */
err = pthread_create(&playback_id, NULL,
@@ -188,7 +189,7 @@ static void test_loopback(struct bat *bat)
/* TODO: use a pipe to signal stream start etc - i.e. to sync threads */
/* Let some time for playing something before capturing */
- usleep(CAPTURE_DELAY * 1000);
+ nanosleep(&capture_delay, NULL);
/* start capture */
err = pthread_create(&capture_id, NULL, (void *) bat->capture.fct, bat);
@@ -691,7 +692,7 @@ int main(int argc, char *argv[])
}
/* Waiting 500ms and start the next round */
- usleep(CAPTURE_DELAY * 1000);
+ nanosleep(&capture_delay, NULL);
}
goto out;
}
--
2.17.1
More information about the Alsa-devel
mailing list