{"id":14862,"url":"https://patchwork.libcamera.org/api/patches/14862/?format=json","web_url":"https://patchwork.libcamera.org/patch/14862/","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":"<20211130033820.18235-9-laurent.pinchart@ideasonboard.com>","date":"2021-11-30T03:38:06","name":"[libcamera-devel,v4,08/22] libcamera: event_dispatcher_poll: Manage fd by UniqueFD","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"5282388199e1174f679f94257d441715ce0b5b04","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14862/mbox/","series":[{"id":2776,"url":"https://patchwork.libcamera.org/api/series/2776/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2776","date":"2021-11-30T03:37:58","name":"libcamera: Introduce UniqueFD","version":4,"mbox":"https://patchwork.libcamera.org/series/2776/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14862/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14862/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 4E725C324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 03:39:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DAF3B605C8;\n\tTue, 30 Nov 2021 04:39:01 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C02B3605C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:38:51 +0100 (CET)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 580118F0;\n\tTue, 30 Nov 2021 04:38:51 +0100 (CET)"],"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=\"dIWiFPW7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638243531;\n\tbh=ADcLrnJXMzRoiajlsZF9dxsL0AsNDStcNCtprfCjW6I=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=dIWiFPW7pd+pEsJ93XI3baABrZvjYie3PB7/o2/AQe3nRDfbunvw31qa5npMUsMnZ\n\tYZQmlAKjdT2epDXh5WRLMxUhYq4NKhYJFRFQ7Em3q1dkFf13pu7hB16BqNsPkyAJd7\n\tazYO2hnevso7gsV1nAmO7J7VoFvWAB/rW/sG7IBE=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 30 Nov 2021 05:38:06 +0200","Message-Id":"<20211130033820.18235-9-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20211130033820.18235-1-laurent.pinchart@ideasonboard.com>","References":"<20211130033820.18235-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 08/22] libcamera:\n\tevent_dispatcher_poll: Manage fd by UniqueFD","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":"From: Hirokazu Honda <hiroh@chromium.org>\n\nManages the event file descriptor owned by EventDispatcherPoll\nby UniqueFD.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/base/event_dispatcher_poll.h |  3 ++-\n src/libcamera/base/event_dispatcher_poll.cpp   | 11 +++++------\n 2 files changed, 7 insertions(+), 7 deletions(-)","diff":"diff --git a/include/libcamera/base/event_dispatcher_poll.h b/include/libcamera/base/event_dispatcher_poll.h\nindex 3d2fc7bbc4c3..b7840309bb25 100644\n--- a/include/libcamera/base/event_dispatcher_poll.h\n+++ b/include/libcamera/base/event_dispatcher_poll.h\n@@ -14,6 +14,7 @@\n #include <libcamera/base/private.h>\n \n #include <libcamera/base/event_dispatcher.h>\n+#include <libcamera/base/unique_fd.h>\n \n struct pollfd;\n \n@@ -50,7 +51,7 @@ private:\n \n \tstd::map<int, EventNotifierSetPoll> notifiers_;\n \tstd::list<Timer *> timers_;\n-\tint eventfd_;\n+\tUniqueFD eventfd_;\n \n \tbool processingEvents_;\n };\ndiff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp\nindex 3c9a126c0bd6..8ee22d5adcc4 100644\n--- a/src/libcamera/base/event_dispatcher_poll.cpp\n+++ b/src/libcamera/base/event_dispatcher_poll.cpp\n@@ -54,14 +54,13 @@ EventDispatcherPoll::EventDispatcherPoll()\n \t * Create the event fd. Failures are fatal as we can't implement an\n \t * interruptible dispatcher without the fd.\n \t */\n-\teventfd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);\n-\tif (eventfd_ < 0)\n+\teventfd_ = UniqueFD(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK));\n+\tif (!eventfd_.isValid())\n \t\tLOG(Event, Fatal) << \"Unable to create eventfd\";\n }\n \n EventDispatcherPoll::~EventDispatcherPoll()\n {\n-\tclose(eventfd_);\n }\n \n void EventDispatcherPoll::registerEventNotifier(EventNotifier *notifier)\n@@ -154,7 +153,7 @@ void EventDispatcherPoll::processEvents()\n \tfor (auto notifier : notifiers_)\n \t\tpollfds.push_back({ notifier.first, notifier.second.events(), 0 });\n \n-\tpollfds.push_back({ eventfd_, POLLIN, 0 });\n+\tpollfds.push_back({ eventfd_.get(), POLLIN, 0 });\n \n \t/* Wait for events and process notifiers and timers. */\n \tdo {\n@@ -176,7 +175,7 @@ void EventDispatcherPoll::processEvents()\n void EventDispatcherPoll::interrupt()\n {\n \tuint64_t value = 1;\n-\tssize_t ret = write(eventfd_, &value, sizeof(value));\n+\tssize_t ret = write(eventfd_.get(), &value, sizeof(value));\n \tif (ret != sizeof(value)) {\n \t\tif (ret < 0)\n \t\t\tret = -errno;\n@@ -230,7 +229,7 @@ void EventDispatcherPoll::processInterrupt(const struct pollfd &pfd)\n \t\treturn;\n \n \tuint64_t value;\n-\tssize_t ret = read(eventfd_, &value, sizeof(value));\n+\tssize_t ret = read(eventfd_.get(), &value, sizeof(value));\n \tif (ret != sizeof(value)) {\n \t\tif (ret < 0)\n \t\t\tret = -errno;\n","prefixes":["libcamera-devel","v4","08/22"]}