All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Takashi Iwai <tiwai@suse.de>, alsa-devel@alsa-project.org
Subject: Re: [PATCH RFC alsa-lib 1/5] pcm: Add thread-safety to	PCM API
Date: Tue, 5 Jul 2016 18:30:36 +0200	[thread overview]
Message-ID: <9a7af148-48cf-cb92-7e91-9dce9de7c381@ladisch.de> (raw)
In-Reply-To: <20160705152024.20152-2-tiwai@suse.de>

Takashi Iwai wrote:
> --- a/src/pcm/pcm.c
> +++ b/src/pcm/pcm.c
> @@ -686,6 +686,8 @@ snd_pcm_stream_t snd_pcm_stream(snd_pcm_t *pcm)
>   *
>   * Closes the specified PCM handle and frees all associated
>   * resources.
> + *
> + * The function is thread-safe when built with the proper option.
>   */
>  int snd_pcm_close(snd_pcm_t *pcm)
>  {
> @@ -697,6 +699,7 @@ int snd_pcm_close(snd_pcm_t *pcm)
>  		if (err < 0)
>  			res = err;
>  	}
> +	snd_pcm_lock(pcm);
>  	if (pcm->mmap_channels)
>  		snd_pcm_munmap(pcm);
>  	while (!list_empty(&pcm->async_handlers)) {
> @@ -704,6 +707,7 @@ int snd_pcm_close(snd_pcm_t *pcm)
>  		snd_async_del_handler(h);
>  	}
>  	err = pcm->ops->close(pcm->op_arg);
> +	snd_pcm_unlock(pcm);
>  	if (err < 0)
>  		res = err;
>  	err = snd_pcm_free(pcm);

Thread safety does not really make sense for a destructor like
snd_pcm_close().  If any other code is accessing the device at the same
time, the freeing will make it crash anyway.

What would make sense would be to output a debug warning if the device
is locked, and/or to poison the device (maybe ->ops = NULL).


Regards,
Clemens

  reply	other threads:[~2016-07-05 16:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 15:20 [PATCH RFC alsa-lib 0/5] Add thread-safety to PCM API Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 1/5] pcm: " Takashi Iwai
2016-07-05 16:30   ` Clemens Ladisch [this message]
2016-07-05 16:36     ` Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 2/5] test: Add pcm-multi-thread program Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 3/5] Add pcm-multi-thread to .gitignore Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 4/5] pcm: Remove superfluous rmb() from PCM meter plugin Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 5/5] pcm: Remove home brew atomic operations 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=9a7af148-48cf-cb92-7e91-9dce9de7c381@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.