Patch Detail
Show a patch.
GET /api/patches/14963/?format=api
{ "id": 14963, "url": "https://patchwork.libcamera.org/api/patches/14963/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14963/", "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": "<20211201142936.107405-4-jacopo@jmondi.org>", "date": "2021-12-01T14:29:28", "name": "[libcamera-devel,v4,03/11] libcamera: fence: Introduce Fence", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "e94d11358fd516519ffeb51f825ccca4f6abd388", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": { "id": 15, "url": "https://patchwork.libcamera.org/api/users/15/?format=api", "username": "jmondi", "first_name": "Jacopo", "last_name": "Mondi", "email": "jacopo@jmondi.org" }, "mbox": "https://patchwork.libcamera.org/patch/14963/mbox/", "series": [ { "id": 2795, "url": "https://patchwork.libcamera.org/api/series/2795/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2795", "date": "2021-12-01T14:29:25", "name": "libcamera: Add support for Fence", "version": 4, "mbox": "https://patchwork.libcamera.org/series/2795/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14963/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14963/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 8112FC3250\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 1 Dec 2021 14:28:54 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 075B460746;\n\tWed, 1 Dec 2021 15:28:54 +0100 (CET)", "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 785216073C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 1 Dec 2021 15:28:52 +0100 (CET)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id B91B1C0005;\n\tWed, 1 Dec 2021 14:28:51 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 1 Dec 2021 15:29:28 +0100", "Message-Id": "<20211201142936.107405-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.33.1", "In-Reply-To": "<20211201142936.107405-1-jacopo@jmondi.org>", "References": "<20211201142936.107405-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 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>\n---\n include/libcamera/fence.h | 31 ++++++++++\n include/libcamera/meson.build | 1 +\n src/libcamera/fence.cpp | 113 ++++++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 146 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..bd737e9848e1\n--- /dev/null\n+++ b/src/libcamera/fence.cpp\n@@ -0,0 +1,113 @@\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 Synchronization fence\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+ * Synchronization fences are most commonly used in association with frame\n+ * buffers. A FrameBuffer can be associated with a Fence so that the library can\n+ * wait for the Fence to be signalled before allowing the camera device to\n+ * actually access the memory area described by the FrameBuffer.\n+ *\n+ * \\sa Request::addBuffer()\n+ *\n+ * By using synchronization fences, application can then synchronize between\n+ * frame buffer consumers and producers, as for example a display device and a\n+ * camera, to guarantee that new data transfers only happen once the existing\n+ * frames have 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+ * kernel sync file. This is currently the only mechanism supported by\n+ * libcamera, but others can be implemented by extending or subclassing this\n+ * class and implementing opportune handling in the core library.\n+ *\n+ * <a href=\"https://www.kernel.org/doc/html/latest/driver-api/sync_file.html\">kernel sync file</a>\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 synchronization fence\n+ * \\param[in] fd The synchronization 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 b763110e74a6..b4882a2577f5 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -14,6 +14,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", "v4", "03/11" ] }