[{"id":34728,"web_url":"https://patchwork.libcamera.org/comment/34728/","msgid":"<175127242065.2340557.11505298535379477422@ping.linuxembedded.co.uk>","date":"2025-06-30T08:33:40","subject":"Re: [PATCH v1 6/6] libcamera: pipeline_handler: cancel waiting\n\trequests first","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-06-30 09:11:21)\n> From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> When stopping a camera, we may now find that there are requests\n> queued to the camera but not yet available in the pipeline handler.\n> \n> These are \"waitingReqeusts\" which are not yet queued to the device.\n> \n> While stopping a camera, we ask the pipeline to stop with stopDevice()\n> and then cancel any waiting requests after.\n> \n> This however can lead to a race where having stopped the camera and\n> completed the requests, the pipeline may try to further consume requests\n> from the waiting lists.\n> \n> Therefore empty the waitingRequests queue before stopping the device and\n> cancel the waitingRequests afterwards.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nThat's most of a rewrite - so I don't know who the author is now - but\nindeed, based on previous review comments this looks good to me!\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n... But I'm reviewing your modifications not a patch I wrote ;-) \n\n\n> ---\n>  src/libcamera/pipeline_handler.cpp | 18 +++++++++++++-----\n>  1 file changed, 13 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\n> index 383c6ad0c4aa..207a2bae96d6 100644\n> --- a/src/libcamera/pipeline_handler.cpp\n> +++ b/src/libcamera/pipeline_handler.cpp\n> @@ -364,20 +364,28 @@ void PipelineHandler::unlockMediaDevices()\n>   */\n>  void PipelineHandler::stop(Camera *camera)\n>  {\n> +       /*\n> +        * Take all waiting requests so that they are not requeued in response\n> +        * to completeRequest() being called inside stopDevice(). Cancel them\n> +        * after the device to keep them in order.\n> +        */\n> +       Camera::Private *data = camera->_d();\n> +       std::queue<Request *> waitingRequests;\n> +       waitingRequests.swap(data->waitingRequests_);\n> +\n>         /* Stop the pipeline handler and let the queued requests complete. */\n>         stopDevice(camera);\n>  \n> -       Camera::Private *data = camera->_d();\n> -\n>         /* Cancel and signal as complete all waiting requests. */\n> -       while (!data->waitingRequests_.empty()) {\n> -               Request *request = data->waitingRequests_.front();\n> -               data->waitingRequests_.pop();\n> +       while (!waitingRequests.empty()) {\n> +               Request *request = waitingRequests.front();\n> +               waitingRequests.pop();\n>                 cancelRequest(request);\n>         }\n>  \n>         /* Make sure no requests are pending. */\n>         ASSERT(data->queuedRequests_.empty());\n> +       ASSERT(data->waitingRequests_.empty());\n>  \n>         data->requestSequence_ = 0;\n>  }\n> -- \n> 2.48.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A4166BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 30 Jun 2025 08:33:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C685168E05;\n\tMon, 30 Jun 2025 10:33:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5031761529\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Jun 2025 10:33:43 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A04456BE;\n\tMon, 30 Jun 2025 10:33:21 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Kk7AEfrs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1751272401;\n\tbh=kxAu9hd/juNj4nbHsZd2mvDmNSOBZ9W5qDbMgEcDgX0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Kk7AEfrsle2eGd4XvHX6ThcF2O8mAT4kYMskQ1XuwVzf/XpJYPYSRCNKWPo4nJMf6\n\tr1c32t5/WKhTtIvRtZwht6QcVI1bKJa+cIjdSNxdYW9iMcaODFp3oqsiuGBYi6VdAo\n\tfzPI/JOmddfbFEtHiFCasyPCuUrc//myQEowZ+uA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250630081126.2384387-7-stefan.klug@ideasonboard.com>","References":"<20250630081126.2384387-1-stefan.klug@ideasonboard.com>\n\t<20250630081126.2384387-7-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v1 6/6] libcamera: pipeline_handler: cancel waiting\n\trequests first","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 30 Jun 2025 09:33:40 +0100","Message-ID":"<175127242065.2340557.11505298535379477422@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]