Patch Detail
Show a patch.
GET /api/patches/21554/?format=api
{ "id": 21554, "url": "https://patchwork.libcamera.org/api/patches/21554/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21554/", "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": "<20241009074642.2965791-3-chenghaoyang@chromium.org>", "date": "2024-10-09T07:41:20", "name": "[2/5] libcamera: Add template for pool implementation", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "132b7321703a5412e549f62c7918b73f3665b62b", "submitter": { "id": 117, "url": "https://patchwork.libcamera.org/api/people/117/?format=api", "name": "Cheng-Hao Yang", "email": "chenghaoyang@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21554/mbox/", "series": [ { "id": 4670, "url": "https://patchwork.libcamera.org/api/series/4670/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4670", "date": "2024-10-09T07:41:18", "name": "Add InfoFrame", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4670/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21554/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21554/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 77108C32E7\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 9 Oct 2024 07:46:56 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 52EAE6536F;\n\tWed, 9 Oct 2024 09:46:55 +0200 (CEST)", "from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com\n\t[IPv6:2607:f8b0:4864:20::102f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F17D56536F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 9 Oct 2024 09:46:51 +0200 (CEST)", "by mail-pj1-x102f.google.com with SMTP id\n\t98e67ed59e1d1-2e199b1d157so4773870a91.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 09 Oct 2024 00:46:51 -0700 (PDT)", "from chenghaoyang-low.c.googlers.com.com\n\t(199.211.81.34.bc.googleusercontent.com. [34.81.211.199])\n\tby smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-2e2a57077c2sm944414a91.17.2024.10.09.00.46.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 09 Oct 2024 00:46:49 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"GXEC7gYw\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1728460010; x=1729064810;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=KTpmD1L4y0v1O2KJieH/lIMmNmwARc2tg5l3xqlLN5k=;\n\tb=GXEC7gYwNyE0EdxSlxG8V+hoLMuJAIz3f0ggY8IY770BnZ+8u1WCWu93oQIVzvMvyG\n\teGd9K7xdD5YKWw85hqI/8ibvolXm2uHpVDKcGBU4yNu/1NA/l4rLENRBCbCxDryRhTe6\n\tVmLKEqksoAuFAjdhGcWrRKewjmvK2EOWkV8Rc=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1728460010; x=1729064810;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=KTpmD1L4y0v1O2KJieH/lIMmNmwARc2tg5l3xqlLN5k=;\n\tb=ss7mk/Edg2Z6Sr2gtfEQKt/5xZ6JyMjcnHKQvgd0NOHkUcvH0wZja0XI8HwNS0LTSu\n\t2oSOxt4ZsEsZ6/oG17TVbNdQgbks1Hy8l7GgjV+vqzQg4t0J4ibqUYGymTsWYS/0zEqN\n\t2xqr8lYY0mooK1He+2ckq7r1SSFvK5TCz601m7FZ1molQdy78/X/T6//L1y+rr3hXrlK\n\to4JOFqvk7kn0ucXK0OeYPeX9k1h8sXCl6YR+Dq0HHoNG+hxEt8pEcxFvGgHNrGqIgBaj\n\t90bv+aQQKwvQlo5gkiwamptGfs1/q4z/oRfdrAfzTbv213R7LMzPpdn88O96DBDIQ4z8\n\t5puw==", "X-Gm-Message-State": "AOJu0YwzH/cF6b4zDF5rBUWzxaSlsLQsHBrH2/bzldQTr+zKj7NNJLS2\n\t6raa2Uw3P7OQlNfUCwGczoaqaIlss3LFfouBTT5UP/zLjmYt3RnsPYUvhjIqRKkL9x5DMCAqCtI\n\t=", "X-Google-Smtp-Source": "AGHT+IEJ0Tjw06HXoNrNo4fgOVUUvOOBohGqPp62OkvEdQ4WaOAkT8/2erOwp3jlgvr66Eb+rsqIKg==", "X-Received": "by 2002:a17:90b:fc8:b0:2d8:f7c6:e1dd with SMTP id\n\t98e67ed59e1d1-2e2a25a04e1mr1904759a91.37.1728460010206; \n\tWed, 09 Oct 2024 00:46:50 -0700 (PDT)", "From": "Harvey Yang <chenghaoyang@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Harvey Yang <chenghaoyang@chromium.org>,\n\tHan-Lin Chen <hanlinchen@chromium.org>", "Subject": "[PATCH 2/5] libcamera: Add template for pool implementation", "Date": "Wed, 9 Oct 2024 07:41:20 +0000", "Message-ID": "<20241009074642.2965791-3-chenghaoyang@chromium.org>", "X-Mailer": "git-send-email 2.47.0.rc0.187.ge670bccf7e-goog", "In-Reply-To": "<20241009074642.2965791-1-chenghaoyang@chromium.org>", "References": "<20241009074642.2965791-1-chenghaoyang@chromium.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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": "Add a template helper class as a Pool, which owns a list of objects that\nallows requesting and recycling objects. Mostly used as buffer pools.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\nCo-developed-by: Harvey Yang <chenghaoyang@chromium.org>\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n include/libcamera/internal/meson.build | 1 +\n include/libcamera/internal/pool.h | 119 +++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/pool.cpp | 70 +++++++++++++++\n 4 files changed, 191 insertions(+)\n create mode 100644 include/libcamera/internal/pool.h\n create mode 100644 src/libcamera/pool.cpp", "diff": "diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 4c1228b95..b78e51d0b 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -32,6 +32,7 @@ libcamera_internal_headers = files([\n 'media_device.h',\n 'media_object.h',\n 'pipeline_handler.h',\n+ 'pool.h',\n 'process.h',\n 'pub_key.h',\n 'request.h',\ndiff --git a/include/libcamera/internal/pool.h b/include/libcamera/internal/pool.h\nnew file mode 100644\nindex 000000000..578c6dd12\n--- /dev/null\n+++ b/include/libcamera/internal/pool.h\n@@ -0,0 +1,119 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Google Inc.\n+ *\n+ * pool.h - Template class for generic pool\n+ *\n+ * Common usage:\n+ *\n+ * Unique tokens:\n+ * Pool<uint32_t, BasicContainer<uint32_t>>;\n+ *\n+ * Auto closed Fds:\n+ * Pool<int, UniqueFD>;\n+ *\n+ * Auto destructed FrameBuffers:\n+ * Pool<FrameBuffer *, std::unique_ptr<FrameBuffer>>;\n+ */\n+\n+#pragma once\n+\n+#include <algorithm>\n+#include <deque>\n+#include <set>\n+#include <string>\n+#include <vector>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/mutex.h>\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Pool)\n+\n+template<typename T, typename UniquePtr>\n+class Pool : public Loggable\n+{\n+public:\n+\tPool() = default;\n+\t~Pool() = default;\n+\n+\t/* Loggable */\n+\tstd::string logPrefix() const override { return \"Pool\"; }\n+\n+\tvoid setData(std::vector<UniquePtr> &pool)\n+\t{\n+\t\tpool_.swap(pool);\n+\t\tfree_.clear();\n+\t\tinUse_.clear();\n+\n+\t\tfor (auto &fd : pool_) {\n+\t\t\tfree_.emplace_back(fd.get());\n+\t\t}\n+\t}\n+\n+\tvoid release()\n+\t{\n+\t\tpool_.clear();\n+\t\tfree_.clear();\n+\t\tinUse_.clear();\n+\t}\n+\n+\tstd::vector<UniquePtr> &content()\n+\t{\n+\t\treturn pool_;\n+\t}\n+\n+\tsize_t size()\n+\t{\n+\t\treturn pool_.size();\n+\t}\n+\n+\tT get()\n+\t{\n+\t\tstd::scoped_lock lock(mutex_);\n+\n+\t\tif (free_.empty())\n+\t\t\tLOG(Pool, Fatal) << \"not enough data in the Pool\";\n+\n+\t\tT fd = free_.front();\n+\t\tfree_.pop_front();\n+\t\tinUse_.emplace(fd);\n+\n+\t\treturn fd;\n+\t}\n+\n+\tvoid put(T data)\n+\t{\n+\t\tstd::scoped_lock lock(mutex_);\n+\n+\t\tauto iter = std::find(inUse_.begin(), inUse_.end(), data);\n+\t\tif (iter == inUse_.end())\n+\t\t\tLOG(Pool, Fatal) << \"return data not belonging to the pool\";\n+\n+\t\tinUse_.erase(iter);\n+\t\tfree_.emplace_front(data);\n+\t}\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY_AND_MOVE(Pool)\n+\n+\tstd::vector<UniquePtr> pool_;\n+\tstd::deque<T> free_;\n+\tstd::set<T> inUse_;\n+\tMutex mutex_;\n+};\n+\n+template<typename T>\n+class BasicContainer\n+{\n+public:\n+\tBasicContainer(T &value)\n+\t\t: value_(value) {}\n+\tT get() { return value_; }\n+\n+private:\n+\tT value_;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 6c3ef5377..f4403687a 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -43,6 +43,7 @@ libcamera_internal_sources = files([\n 'media_device.cpp',\n 'media_object.cpp',\n 'pipeline_handler.cpp',\n+ 'pool.cpp',\n 'process.cpp',\n 'pub_key.cpp',\n 'shared_mem_object.cpp',\ndiff --git a/src/libcamera/pool.cpp b/src/libcamera/pool.cpp\nnew file mode 100644\nindex 000000000..122b025d1\n--- /dev/null\n+++ b/src/libcamera/pool.cpp\n@@ -0,0 +1,70 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Google Inc.\n+ *\n+ * pool.cpp - Template class for generic pool\n+ */\n+\n+/**\n+ * \\class libcamera::Pool\n+ * \\brief Pool that owns a list of objects\n+ *\n+ * A Pool that owns a list of objects, and allows users to request objects and\n+ * recycle them. It's mostly used as a buffer pool, holding a list of buffers\n+ * as std::unique_ptr.\n+ */\n+\n+/**\n+ * \\fn Pool::setData(std::vector<UniquePtr> &pool)\n+ * \\brief Set and claim ownership of objects. Swap the previously owned objects\n+ * not empty.\n+ * \\param[inout] pool The objects to be set and the swapped out ones\n+ */\n+\n+/**\n+ * \\fn Pool::release()\n+ * \\brief Release the ownership of objects and reset states\n+ */\n+\n+/**\n+ * \\fn Pool::content()\n+ * \\return The reference of objects\n+ */\n+\n+/**\n+ * \\fn Pool::size()\n+ * \\brief The size of objects\n+ */\n+\n+/**\n+ * \\fn Pool::get()\n+ * \\brief Get one object. Fatal if there's none available\n+ *\n+ * \\return An available object\n+ */\n+\n+/**\n+ * \\fn Pool::put(T data)\n+ * \\brief Recycle one object that was retrieved by get()\n+ * \\param[in] data The object to be recycled\n+ */\n+\n+/**\n+ * \\class libcamera::BasicContainer\n+ * \\brief A container for basic types\n+ *\n+ * When using Pool with a basic type (e.g. `int`), it'd be easier to get an\n+ * object by value instead of by pointer. BasicContainer makes it possible as a\n+ * helper class.\n+ */\n+\n+/**\n+ * \\fn BasicContainer::BasicContainer(T &value)\n+ * \\brief Create a BasicContainer with a value\n+ * \\param[in] value The value to be contained\n+ */\n+\n+/**\n+ * \\fn BasicContainer::get()\n+ * \\return Return the object by value\n+ */\n", "prefixes": [ "2/5" ] }