From patchwork Thu Mar 22 13:48:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10301563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E645C60216 for ; Thu, 22 Mar 2018 13:49:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D813228445 for ; Thu, 22 Mar 2018 13:49:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA2572844C; Thu, 22 Mar 2018 13:49:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD13628445 for ; Thu, 22 Mar 2018 13:49:43 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id AFD372673CF; Thu, 22 Mar 2018 14:49:42 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 518152673C7; Thu, 22 Mar 2018 14:49:40 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by alsa0.perex.cz (Postfix) with ESMTP id 811262673B2 for ; Thu, 22 Mar 2018 14:49:37 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 15E0A3C07DE; Thu, 22 Mar 2018 14:49:37 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id obwQ6ybVObGg; Thu, 22 Mar 2018 14:49:30 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 7ED563C07DC; Thu, 22 Mar 2018 14:49:30 +0100 (CET) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.382.0; Thu, 22 Mar 2018 14:49:30 +0100 From: To: Date: Thu, 22 Mar 2018 14:48:56 +0100 Message-ID: <1521726537-7651-2-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521726537-7651-1-git-send-email-twischer@de.adit-jv.com> References: <1521726537-7651-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - IOPLUG DRAIN 1/1] ioplug: drain: Wait with pollwhen EAGAIN in blocking mode X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" 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 X-Virus-Scanned: ClamAV using ClamSMTP From: Timo Wischer With this changes an IO plugin should not block by it self in the its own snd_pcm_drain() implementation. It should return -EAGAIN and inform the ALSA library via the poll_descriptors that draining is done. In non-blocking mode this implementation expects that the user blocks on the poll_descriptors whenever snd_pcm_drain() returns -EAGAIN. In addition the user has to call snd_pcm_drain() again to check if draining is really done. This change will not harm existing IO plugins which are blocking in its snd_pcm_drain() callback. Signed-off-by: Timo Wischer diff --git a/include/pcm_ioplug.h b/include/pcm_ioplug.h index c1310e3..aa08962 100644 --- a/include/pcm_ioplug.h +++ b/include/pcm_ioplug.h @@ -169,6 +169,12 @@ struct snd_pcm_ioplug_callback { int (*prepare)(snd_pcm_ioplug_t *io); /** * drain; optional + * This function should never block. It should return -EAGAIN in case of + * it is not yet done. In this case it will be called again by the ALSA + * library (in blocking mode) or by the user (in non blocking mode). + * In case of -EAGAIN the poll_descriptors have to be used to inform the + * ALSA library that draining is possibly done and this callback has to + * be called again. */ int (*drain)(snd_pcm_ioplug_t *io); /** diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c index 8c0ed48..7682dcd 100644 --- a/src/pcm/pcm_ioplug.c +++ b/src/pcm/pcm_ioplug.c @@ -492,17 +492,37 @@ static int snd_pcm_ioplug_drop(snd_pcm_t *pcm) static int snd_pcm_ioplug_drain(snd_pcm_t *pcm) { ioplug_priv_t *io = pcm->private_data; - int err; + int err = 0; if (io->data->state == SND_PCM_STATE_OPEN) return -EBADFD; io->data->state = SND_PCM_STATE_DRAINING; - if (io->data->callback->drain) - io->data->callback->drain(io->data); - snd_pcm_lock(pcm); - err = snd_pcm_ioplug_drop(pcm); - snd_pcm_unlock(pcm); + if (io->data->callback->drain) { + err = io->data->callback->drain(io->data); + + /* in blocking mode wait unti draining is done or + * an issue was detected. + */ + if (!io->data->nonblock) { + while (err == -EAGAIN) { + snd_pcm_lock(pcm); + err = snd_pcm_wait_nocheck(pcm, -1); + snd_pcm_unlock(pcm); + if (err < 0) + break; + err = io->data->callback->drain(io->data); + } + } + } + + /* only drop if draining is done or there was an issue */ + if (err != -EAGAIN) { + snd_pcm_lock(pcm); + err = snd_pcm_ioplug_drop(pcm); + snd_pcm_unlock(pcm); + } + return err; }