[{"id":21337,"web_url":"https://patchwork.libcamera.org/comment/21337/","msgid":"<20211129151803.otvn55lqcopogct4@uno.localdomain>","date":"2021-11-29T15:18:03","subject":"Re: [libcamera-devel] [PATCH v3 08/17] libcamera:\n\tevent_dispatcher_poll: Manage fd by UniqueFD","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Mon, Nov 29, 2021 at 01:57:43AM +0200, Laurent Pinchart wrote:\n> From: Hirokazu Honda <hiroh@chromium.org>\n>\n> Manages the event file descriptor owned by EventDispatcherPoll\n> by UniqueFD.\n>\n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\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(-)\n>\n> diff --git a/include/libcamera/base/event_dispatcher_poll.h b/include/libcamera/base/event_dispatcher_poll.h\n> index 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>  };\n> diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp\n> index 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> --\n> Regards,\n>\n> Laurent Pinchart\n>","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 EF3DCBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Nov 2021 15:17:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5A4FB605A5;\n\tMon, 29 Nov 2021 16:17:11 +0100 (CET)","from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B8E346059E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Nov 2021 16:17:10 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 3DD8840012;\n\tMon, 29 Nov 2021 15:17:10 +0000 (UTC)"],"Date":"Mon, 29 Nov 2021 16:18:03 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20211129151803.otvn55lqcopogct4@uno.localdomain>","References":"<20211128235752.10836-1-laurent.pinchart@ideasonboard.com>\n\t<20211128235752.10836-9-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211128235752.10836-9-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 08/17] 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]