Patch Detail
Show a patch.
GET /api/patches/15138/?format=api
{ "id": 15138, "url": "https://patchwork.libcamera.org/api/patches/15138/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15138/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20211211165714.23067-4-jacopo@jmondi.org>", "date": "2021-12-11T16:57:06", "name": "[libcamera-devel,v6,03/11] libcamera: fence: Introduce Fence", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "6adf1c8a343724e1026b9d63cf853a3e879dd8e4", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15138/mbox/", "series": [ { "id": 2838, "url": "https://patchwork.libcamera.org/api/series/2838/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2838", "date": "2021-12-11T16:57:03", "name": "libcamera: Add Fence support", "version": 6, "mbox": "https://patchwork.libcamera.org/series/2838/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15138/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15138/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 D8112BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 11 Dec 2021 16:56:31 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6152760822;\n\tSat, 11 Dec 2021 17:56:30 +0100 (CET)", "from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3AD2F60113\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 Dec 2021 17:56:27 +0100 (CET)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 9C3F320009;\n\tSat, 11 Dec 2021 16:56:26 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 11 Dec 2021 17:57:06 +0100", "Message-Id": "<20211211165714.23067-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.33.1", "In-Reply-To": "<20211211165714.23067-1-jacopo@jmondi.org>", "References": "<20211211165714.23067-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v6 03/11] libcamera: fence: Introduce Fence", "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>" }, "content": "Introduce a Fence class which models a synchronization primitive that\nallows to notify the availability of a resource.\n\nThe Fence is modeled as a wrapper of a UniqueFD instance where\nread events are used to signal the Fence. The class can be later\nextended to support additional signalling mechanisms.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/fence.h | 31 ++++++++++\n include/libcamera/meson.build | 1 +\n src/libcamera/fence.cpp | 112 ++++++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 145 insertions(+)\n create mode 100644 include/libcamera/fence.h\n create mode 100644 src/libcamera/fence.cpp", "diff": "diff --git a/include/libcamera/fence.h b/include/libcamera/fence.h\nnew file mode 100644\nindex 000000000000..c0c916c264b4\n--- /dev/null\n+++ b/include/libcamera/fence.h\n@@ -0,0 +1,31 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * internal/fence.h - Synchronization fence\n+ */\n+\n+#pragma once\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/base/unique_fd.h>\n+\n+namespace libcamera {\n+\n+class Fence\n+{\n+public:\n+\tFence(UniqueFD fd);\n+\n+\tbool isValid() const { return fd_.isValid(); }\n+\tconst UniqueFD &fd() const { return fd_; }\n+\n+\tUniqueFD release() { return std::move(fd_); }\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY_AND_MOVE(Fence)\n+\n+\tUniqueFD fd_;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 5f42977c034b..8c2cae00d877 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -6,6 +6,7 @@ libcamera_public_headers = files([\n 'camera.h',\n 'camera_manager.h',\n 'controls.h',\n+ 'fence.h',\n 'framebuffer.h',\n 'framebuffer_allocator.h',\n 'geometry.h',\ndiff --git a/src/libcamera/fence.cpp b/src/libcamera/fence.cpp\nnew file mode 100644\nindex 000000000000..7b784778320a\n--- /dev/null\n+++ b/src/libcamera/fence.cpp\n@@ -0,0 +1,112 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * fence.cpp - Synchronization fence\n+ */\n+\n+#include \"libcamera/fence.h\"\n+\n+namespace libcamera {\n+\n+/**\n+ *\n+ * \\file libcamera/fence.h\n+ * \\brief Definition of the Fence class\n+ */\n+\n+/**\n+ * \\class Fence\n+ * \\brief Synchronization primitive to manage resources\n+ *\n+ * The Fence class models a synchronization primitive that can be used by\n+ * applications to explicitly synchronize resource usage, and can be shared by\n+ * multiple processes.\n+ *\n+ * Fences are most commonly used in association with frame buffers. A\n+ * FrameBuffer can be associated with a Fence so that the library can wait for\n+ * the Fence to be signalled before allowing the camera device to actually\n+ * access the memory area described by the FrameBuffer.\n+ *\n+ * \\sa Request::addBuffer()\n+ *\n+ * By using a fence, applications can then synchronize between frame buffer\n+ * consumers and producers, as for example a display device and a camera, to\n+ * guarantee that a new data transfers only happen once the existing frames have\n+ * been displayed.\n+ *\n+ * A Fence can be realized by different event notification primitives, the most\n+ * common of which is represented by waiting for read events to happen on a\n+ * <a href=\"https://www.kernel.org/doc/html/latest/driver-api/sync_file.html\">kernel sync file.</a>\n+ * This is currently the only mechanism supported by libcamera, but others can\n+ * be implemented by extending or subclassing this class and implementing\n+ * opportune handling in the core library.\n+ *\n+ * \\internal\n+ *\n+ * The Fence class is a thin abstraction around a UniqueFD which simply allows\n+ * to access it as a const reference or to move its ownership to the caller.\n+ *\n+ * The usage of the Fence class allows to abstract the underlying\n+ * synchronization mechanism in use and implement an interface towards other\n+ * library components that will not change when new synchronization primitives\n+ * will be added as fences.\n+ *\n+ * A Fence is constructed with a UniqueFD whose ownership is moved in the Fence.\n+ * A FrameBuffer can be associated with a Fence by passing it to the\n+ * Request::addBuffer() function, which will move the Fence into the FrameBuffer\n+ * itself. Once a Request is queued to the Camera, a preparation phase\n+ * guarantees that before actually applying the Request to the hardware, all the\n+ * valid fences of the frame buffers in a Request are correctly signalled. Once\n+ * a Fence has completed, the library will release the FrameBuffer fence so that\n+ * application won't be allowed to access it.\n+ *\n+ * An optional timeout can be started while waiting for a fence to complete. If\n+ * waiting on a Fence fails for whatever reason, the FrameBuffer's fence is not\n+ * reset and is made available to application for them to handle it, by\n+ * releasing the Fence to correctly close the underlying UniqueFD.\n+ *\n+ * A failure in waiting for a Fence to complete will result in the Request to\n+ * complete in failed state.\n+ *\n+ * \\sa Request::prepare()\n+ * \\sa PipelineHandler::doQueueRequests()\n+ */\n+\n+/**\n+ * \\brief Create a Fence\n+ * \\param[in] fd The fence file descriptor\n+ *\n+ * The file descriptor ownership is moved to the Fence.\n+ */\n+Fence::Fence(UniqueFD fd)\n+\t: fd_(std::move(fd))\n+{\n+}\n+\n+/**\n+ * \\fn Fence::isValid()\n+ * \\brief Check if a Fence is valid\n+ *\n+ * A Fence is valid if the file descriptor it wraps is valid.\n+ *\n+ * \\return True if the Fence is valid, false otherwise\n+ */\n+\n+/**\n+ * \\fn Fence::fd()\n+ * \\brief Retrieve a constant reference to the file descriptor\n+ * \\return A const reference to the fence file descriptor\n+ */\n+\n+/**\n+ * \\fn Fence::release()\n+ * \\brief Release the ownership of the file descriptor\n+ *\n+ * Release the ownership of the wrapped file descriptor by returning it to the\n+ * caller.\n+ *\n+ * \\return The wrapper UniqueFD\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 2e54cc04edc7..dc1cc52a427a 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -15,6 +15,7 @@ libcamera_sources = files([\n 'delayed_controls.cpp',\n 'device_enumerator.cpp',\n 'device_enumerator_sysfs.cpp',\n+ 'fence.cpp',\n 'formats.cpp',\n 'framebuffer.cpp',\n 'framebuffer_allocator.cpp',\n", "prefixes": [ "libcamera-devel", "v6", "03/11" ] }