From: Takashi Iwai Subject: Re: [PATCH - JACK 1/1] jack: Use internal snd_pcm_state to reduce amount of additional variables Date: Thu, 15 Mar 2018 16:49:54 +0100 Message-ID: References: <1521118587-6319-1-git-send-email-twischer@de.adit-jv.com> <1521118587-6319-2-git-send-email-twischer@de.adit-jv.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id C4875267252 for ; Thu, 15 Mar 2018 16:49:57 +0100 (CET) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: "Wischer, Timo (ADITG/ESB)" Cc: "alsa-devel@alsa-project.org" List-Id: alsa-devel@alsa-project.org On Thu, 15 Mar 2018 16:07:31 +0100, Wischer, Timo (ADITG/ESB) wrote: > > > We need to check it, of course. But the behavior of the prepare > > function is certainly different from others, so it's more likely a > > bug. > > I could provide a fix for the IO plug API for prepare and draining. Yes, these are very trivial changes. > > This should be notified to ioplug via snd_pcm_ioplug_set_state(). > > Without an additional variable snd_pcm_ioplug_set_state() has to be called from the JACK thread. > But snd_pcm_ioplug_set_state() is not thread safe. Well, but your internal state copy is also not thread safe as of this patch, after all. > > That'd be great if everything is ready, but this can't be a reason to > > add a shadow state and modify the code as in the patch for now. > > At the end I would like to use functions similar to READ_ONCE() and WRITE_ONCE() to access the state (known from the Linux kernel [1]). > But I think this should not be part of the ALSA library because it is for most IO plugins not required. > Therefore I need to have an internal copy of the state which will only be accessed with READ_ONCE() and WRITE_ONCE(). > > You are right, it is not yet required but at the end I have to implement it. > > Do you think we should implement such a synchronization into the ALSA lib? > > [1] https://www.kernel.org/doc/Documentation/memory-barriers.txt I really would like to avoid that, at least, not introducing any dependency into alsa-lib. The usage inside a plugin is another question, and it would depend on the implementation details. A dependency in plugin may cause a messy conflict when different versions are used in a same application. So, in general, it'd be best for a plugin to be self-contained. Takashi