[{"id":17142,"web_url":"https://patchwork.libcamera.org/comment/17142/","msgid":"<YKq8FVObKFJc9WWD@pendragon.ideasonboard.com>","date":"2021-05-23T20:33:25","subject":"Re: [libcamera-devel] [PATCH v4 1/5] libcamera: camera: Make stop()\n\tidempotent","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nícolas,\n\nThank you for the patch.\n\nOn Fri, May 21, 2021 at 10:30:50AM -0300, Nícolas F. R. A. Prado wrote:\n> Make Camera::stop() idempotent so that it can be called in any state and\n> consecutive times. When called in any state other than CameraRunning, it\n> is a no-op. This simplifies the cleanup path for applications.\n> \n> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n> ---\n> Changes in v4:\n> - Thanks to Jacopo:\n>   - Added \\todo in Camera::stop()\n> \n> No changes in v3\n> \n> Changes in v2:\n> - Suggested by Kieran:\n>   - Add new isRunning() function instead of relying on isAccessAllowed()\n> - Suggested by Laurent:\n>   - Make stop()'s description clearer\n> \n>  src/libcamera/camera.cpp | 24 +++++++++++++++++++++---\n>  1 file changed, 21 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 1340c266cc5f..be0428ecbd46 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -347,6 +347,7 @@ public:\n>  \t\tconst std::set<Stream *> &streams);\n>  \t~Private();\n>  \n> +\tbool isRunning() const;\n>  \tint isAccessAllowed(State state, bool allowDisconnected = false,\n>  \t\t\t    const char *from = __builtin_FUNCTION()) const;\n>  \tint isAccessAllowed(State low, State high,\n> @@ -388,6 +389,15 @@ static const char *const camera_state_names[] = {\n>  \t\"Running\",\n>  };\n>  \n> +bool Camera::Private::isRunning() const\n> +{\n> +\tState currentState = state_.load(std::memory_order_acquire);\n> +\tif (currentState == CameraRunning)\n> +\t\treturn true;\n> +\n> +\treturn false;\n\nYou could write this\n\n\treturn state_.load(std::memory_order_acquire) == CameraRunning;\n\nIf that's the only change needed (and assuming you agree) I can handle\nthis when applying the series.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +}\n> +\n>  int Camera::Private::isAccessAllowed(State state, bool allowDisconnected,\n>  \t\t\t\t     const char *from) const\n>  {\n> @@ -1061,9 +1071,10 @@ int Camera::start(const ControlList *controls)\n>   * This method stops capturing and processing requests immediately. All pending\n>   * requests are cancelled and complete synchronously in an error state.\n>   *\n> - * \\context This function may only be called when the camera is in the Running\n> - * state as defined in \\ref camera_operation, and shall be synchronized by the\n> - * caller with other functions that affect the camera state.\n> + * \\context This function may be called in any camera state as defined in \\ref\n> + * camera_operation, and shall be synchronized by the caller with other\n> + * functions that affect the camera state. If called when the camera isn't\n> + * running, it is a no-op.\n>   *\n>   * \\return 0 on success or a negative error code otherwise\n>   * \\retval -ENODEV The camera has been disconnected from the system\n> @@ -1073,6 +1084,13 @@ int Camera::stop()\n>  {\n>  \tPrivate *const d = LIBCAMERA_D_PTR();\n>  \n> +\t/*\n> +\t * \\todo Make calling stop() when not in 'Running' part of the state\n> +\t * machine rather than take this shortcut\n> +\t */\n> +\tif (!d->isRunning())\n> +\t\treturn 0;\n> +\n>  \tint ret = d->isAccessAllowed(Private::CameraRunning);\n>  \tif (ret < 0)\n>  \t\treturn ret;","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 B4D0CC3201\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 23 May 2021 20:33:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 03AA36891D;\n\tSun, 23 May 2021 22:33:31 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 67DDC601A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 May 2021 22:33:29 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D41492A8;\n\tSun, 23 May 2021 22:33:28 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Ls9KKLi7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1621802009;\n\tbh=kIN1GkoCdt4lfrfciovMiznRFz4GezYr/PeneJqIFnQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Ls9KKLi7svWUFUY4tByBEz8CS0CFcuPLBjbIc+NzlMFnWddha3pJ0RNi7bdsfV6qD\n\t/Nh+eNH//A1QJCZIhSIS9lUMffnxYyKPpljWfihT1a+o0nBTZBEH/SI5YJyVqX0dbD\n\tpOmGGPQ1tonsEOqtOcp78SmBzi8wnCl/tx3h5Zfw=","Date":"Sun, 23 May 2021 23:33:25 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4=?= Prado <nfraprado@collabora.com>","Message-ID":"<YKq8FVObKFJc9WWD@pendragon.ideasonboard.com>","References":"<20210521133054.274502-1-nfraprado@collabora.com>\n\t<20210521133054.274502-2-nfraprado@collabora.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20210521133054.274502-2-nfraprado@collabora.com>","Subject":"Re: [libcamera-devel] [PATCH v4 1/5] libcamera: camera: Make stop()\n\tidempotent","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>","Cc":"libcamera-devel@lists.libcamera.org, kernel@collabora.com, =?utf-8?q?A?=\n\t=?utf-8?b?bmRyw6k=?= Almeida <andrealmeid@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":17214,"web_url":"https://patchwork.libcamera.org/comment/17214/","msgid":"<CBLNG8GR0Z38.LLOWMGMTCCVD@notapiano>","date":"2021-05-24T17:25:05","subject":"Re: [libcamera-devel] [PATCH v4 1/5] libcamera: camera: Make stop()\n\tidempotent","submitter":{"id":84,"url":"https://patchwork.libcamera.org/api/people/84/","name":"Nícolas F. R. A. Prado","email":"nfraprado@collabora.com"},"content":"Hi Laurent,\n\nEm 2021-05-23 17:33, Laurent Pinchart escreveu:\n\n> Hi Nícolas,\n>\n> Thank you for the patch.\n>\n> On Fri, May 21, 2021 at 10:30:50AM -0300, Nícolas F. R. A. Prado wrote:\n> > Make Camera::stop() idempotent so that it can be called in any state and\n> > consecutive times. When called in any state other than CameraRunning, it\n> > is a no-op. This simplifies the cleanup path for applications.\n> > \n> > Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n> > ---\n> > Changes in v4:\n> > - Thanks to Jacopo:\n> >   - Added \\todo in Camera::stop()\n> > \n> > No changes in v3\n> > \n> > Changes in v2:\n> > - Suggested by Kieran:\n> >   - Add new isRunning() function instead of relying on isAccessAllowed()\n> > - Suggested by Laurent:\n> >   - Make stop()'s description clearer\n> > \n> >  src/libcamera/camera.cpp | 24 +++++++++++++++++++++---\n> >  1 file changed, 21 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> > index 1340c266cc5f..be0428ecbd46 100644\n> > --- a/src/libcamera/camera.cpp\n> > +++ b/src/libcamera/camera.cpp\n> > @@ -347,6 +347,7 @@ public:\n> >  \t\tconst std::set<Stream *> &streams);\n> >  \t~Private();\n> >  \n> > +\tbool isRunning() const;\n> >  \tint isAccessAllowed(State state, bool allowDisconnected = false,\n> >  \t\t\t    const char *from = __builtin_FUNCTION()) const;\n> >  \tint isAccessAllowed(State low, State high,\n> > @@ -388,6 +389,15 @@ static const char *const camera_state_names[] = {\n> >  \t\"Running\",\n> >  };\n> >  \n> > +bool Camera::Private::isRunning() const\n> > +{\n> > +\tState currentState = state_.load(std::memory_order_acquire);\n> > +\tif (currentState == CameraRunning)\n> > +\t\treturn true;\n> > +\n> > +\treturn false;\n>\n> You could write this\n>\n> return state_.load(std::memory_order_acquire) == CameraRunning;\n>\n> If that's the only change needed (and assuming you agree) I can handle\n> this when applying the series.\n\nNo need, I'll apply this for v5.\n\nThanks,\nNícolas\n\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n> > +}\n> > +\n> >  int Camera::Private::isAccessAllowed(State state, bool allowDisconnected,\n> >  \t\t\t\t     const char *from) const\n> >  {\n> > @@ -1061,9 +1071,10 @@ int Camera::start(const ControlList *controls)\n> >   * This method stops capturing and processing requests immediately. All pending\n> >   * requests are cancelled and complete synchronously in an error state.\n> >   *\n> > - * \\context This function may only be called when the camera is in the Running\n> > - * state as defined in \\ref camera_operation, and shall be synchronized by the\n> > - * caller with other functions that affect the camera state.\n> > + * \\context This function may be called in any camera state as defined in \\ref\n> > + * camera_operation, and shall be synchronized by the caller with other\n> > + * functions that affect the camera state. If called when the camera isn't\n> > + * running, it is a no-op.\n> >   *\n> >   * \\return 0 on success or a negative error code otherwise\n> >   * \\retval -ENODEV The camera has been disconnected from the system\n> > @@ -1073,6 +1084,13 @@ int Camera::stop()\n> >  {\n> >  \tPrivate *const d = LIBCAMERA_D_PTR();\n> >  \n> > +\t/*\n> > +\t * \\todo Make calling stop() when not in 'Running' part of the state\n> > +\t * machine rather than take this shortcut\n> > +\t */\n> > +\tif (!d->isRunning())\n> > +\t\treturn 0;\n> > +\n> >  \tint ret = d->isAccessAllowed(Private::CameraRunning);\n> >  \tif (ret < 0)\n> >  \t\treturn ret;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> --\n> To unsubscribe, send mail to kernel-unsubscribe@lists.collabora.co.uk.","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 B9BAAC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 May 2021 17:25:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2599F68919;\n\tMon, 24 May 2021 19:25:48 +0200 (CEST)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BA649601AA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 May 2021 19:25:46 +0200 (CEST)","from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: nfraprado) with ESMTPSA id 17E1F1F41C05"],"Mime-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","Content-Type":"text/plain; charset=UTF-8","Date":"Mon, 24 May 2021 14:25:05 -0300","Message-Id":"<CBLNG8GR0Z38.LLOWMGMTCCVD@notapiano>","To":"\"Laurent Pinchart\" <laurent.pinchart@ideasonboard.com>","From":"=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>","References":"<20210521133054.274502-1-nfraprado@collabora.com>\n\t<20210521133054.274502-2-nfraprado@collabora.com>\n\t<YKq8FVObKFJc9WWD@pendragon.ideasonboard.com>","In-Reply-To":"<YKq8FVObKFJc9WWD@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 1/5] libcamera: camera: Make stop()\n\tidempotent","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>","Cc":"libcamera-devel@lists.libcamera.org, kernel@collabora.com, =?utf-8?q?A?=\n\t=?utf-8?q?ndr=C3=A9_Almeida?= <andrealmeid@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]