{"id":12747,"url":"https://patchwork.libcamera.org/api/patches/12747/?format=json","web_url":"https://patchwork.libcamera.org/patch/12747/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210629151218.248650-2-nfraprado@collabora.com>","date":"2021-06-29T15:12:14","name":"[libcamera-devel,v10,1/5] libcamera: camera: Make stop() idempotent","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ec422dc6e8d501d95f65f38743fbffbd35c07ab5","submitter":{"id":84,"url":"https://patchwork.libcamera.org/api/people/84/?format=json","name":"Nícolas F. R. A. Prado","email":"nfraprado@collabora.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12747/mbox/","series":[{"id":2192,"url":"https://patchwork.libcamera.org/api/series/2192/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2192","date":"2021-06-29T15:12:13","name":"lc-compliance: Refactor using Googletest","version":10,"mbox":"https://patchwork.libcamera.org/series/2192/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12747/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12747/checks/","tags":{},"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 69E22C321F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Jun 2021 15:13:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 37527684ED;\n\tTue, 29 Jun 2021 17:13:09 +0200 (CEST)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 65706684E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Jun 2021 17:13:08 +0200 (CEST)","from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:bd70:78a1:919c:f01a])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nfraprado)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id A09311F43084;\n\tTue, 29 Jun 2021 16:13:06 +0100 (BST)"],"From":"=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 29 Jun 2021 12:12:14 -0300","Message-Id":"<20210629151218.248650-2-nfraprado@collabora.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20210629151218.248650-1-nfraprado@collabora.com>","References":"<20210629151218.248650-1-nfraprado@collabora.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v10 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":"kernel@collabora.com, =?utf-8?q?Andr=C3=A9_Almeida?=\n\t<andrealmeid@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Make Camera::stop() idempotent so that it can be called in any state and\nconsecutive times. When called in any state other than CameraRunning, it\nis a no-op. This simplifies the cleanup path for applications.\n\nSigned-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nNo changes in v10\n\nNo changes in v9\n\nNo changes in v8\n\nNo changes in v7\n\nNo changes in v6\n\nChanges in v5:\n- Thanks to Laurent:\n  - Simplified isRunning()\n\nChanges in v4:\n- Thanks to Jacopo:\n  - Added \\todo in Camera::stop()\n\nNo changes in v3\n\nChanges 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 | 20 +++++++++++++++++---\n 1 file changed, 17 insertions(+), 3 deletions(-)","diff":"diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex de0123aeafca..29f2d91d05d3 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -348,6 +348,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@@ -389,6 +390,11 @@ static const char *const camera_state_names[] = {\n \t\"Running\",\n };\n \n+bool Camera::Private::isRunning() const\n+{\n+\treturn state_.load(std::memory_order_acquire) == CameraRunning;\n+}\n+\n int Camera::Private::isAccessAllowed(State state, bool allowDisconnected,\n \t\t\t\t     const char *from) const\n {\n@@ -1062,9 +1068,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@@ -1074,6 +1081,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","prefixes":["libcamera-devel","v10","1/5"]}