Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Rosen Penev <rosenp@gmail.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] alsa-utils: Remove usleep usage
Date: Mon, 02 Sep 2019 09:02:57 +0200	[thread overview]
Message-ID: <s5hftlfji3i.wl-tiwai@suse.de> (raw)
In-Reply-To: <20190902012705.16062-1-rosenp@gmail.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de>
To: Rosen Penev <rosenp@gmail.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: [alsa-devel] [PATCH] alsa-utils: Remove usleep usage
Date: Mon, 02 Sep 2019 09:02:57 +0200	[thread overview]
Message-ID: <s5hftlfji3i.wl-tiwai@suse.de> (raw)
Message-ID: <20190902070257.4VWalr35NdU7QQDNXjdVgFustk05EaBWZsccNf5Gauw@z> (raw)
In-Reply-To: <20190902012705.16062-1-rosenp@gmail.com>

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

  parent reply	other threads:[~2019-09-02  7:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-09-02  7:02   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hftlfji3i.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=rosenp@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox