* [PATCH] alsa-utils: Remove usleep usage
@ 2019-09-02 1:27 Rosen Penev
2019-09-02 1:27 ` [alsa-devel] " Rosen Penev
2019-09-02 7:02 ` Takashi Iwai
0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2019-09-02 1:27 UTC (permalink / raw)
To: alsa-devel
usleep was deprecated in POSIX 2008 and is not available without
deprecated APIs enabled in uClibc-ng.
Signed-off-by: Rosen Penev <rosenp@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
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [alsa-devel] [PATCH] alsa-utils: Remove usleep usage
2019-09-02 1:27 [PATCH] alsa-utils: Remove usleep usage Rosen Penev
@ 2019-09-02 1:27 ` Rosen Penev
2019-09-02 7:02 ` Takashi Iwai
1 sibling, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2019-09-02 1:27 UTC (permalink / raw)
To: alsa-devel
usleep was deprecated in POSIX 2008 and is not available without
deprecated APIs enabled in uClibc-ng.
Signed-off-by: Rosen Penev <rosenp@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
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] alsa-utils: Remove usleep usage
2019-09-02 1:27 [PATCH] alsa-utils: Remove usleep usage Rosen Penev
2019-09-02 1:27 ` [alsa-devel] " Rosen Penev
@ 2019-09-02 7:02 ` Takashi Iwai
2019-09-02 7:02 ` [alsa-devel] " Takashi Iwai
1 sibling, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2019-09-02 7:02 UTC (permalink / raw)
To: Rosen Penev; +Cc: alsa-devel
On Mon, 02 Sep 2019 03:27:05 +0200,
Rosen Penev wrote:
>
> usleep was deprecated in POSIX 2008 and is not available without
> deprecated APIs enabled in uClibc-ng.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Can we check the presence in configure script and add a compat
usleep() wrapper instead? Replacing each place with the open code
using nanosleep() is way too ugly, IMO.
thanks,
Takashi
> ---
> 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
>
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [alsa-devel] [PATCH] alsa-utils: Remove usleep usage
2019-09-02 7:02 ` Takashi Iwai
@ 2019-09-02 7:02 ` Takashi Iwai
0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2019-09-02 7:02 UTC (permalink / raw)
To: Rosen Penev; +Cc: alsa-devel
On Mon, 02 Sep 2019 03:27:05 +0200,
Rosen Penev wrote:
>
> usleep was deprecated in POSIX 2008 and is not available without
> deprecated APIs enabled in uClibc-ng.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Can we check the presence in configure script and add a compat
usleep() wrapper instead? Replacing each place with the open code
using nanosleep() is way too ugly, IMO.
thanks,
Takashi
> ---
> 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
>
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-09-02 7:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 1:27 [PATCH] alsa-utils: Remove usleep usage Rosen Penev
2019-09-02 1:27 ` [alsa-devel] " Rosen Penev
2019-09-02 7:02 ` Takashi Iwai
2019-09-02 7:02 ` [alsa-devel] " Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).