[{"id":21473,"web_url":"https://patchwork.libcamera.org/comment/21473/","msgid":"<20211130221029.r2vennmbuqjnwjwy@uno.localdomain>","date":"2021-11-30T22:10:29","subject":"Re: [libcamera-devel] [PATCH v4.1 20/22] libcamera: base:\n\tshared_fd: Add comparison operators","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Tue, Nov 30, 2021 at 12:29:25PM +0200, Laurent Pinchart wrote:\n> Add == and != comparison operators between two SharedFD instances, and\n> use them to replace manuel get() calls.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> ---\n> Changes since v4:\n>\n> - Fix typos in documentation\n>\n> This patch will move after 21/22 (the fd() to get() rename) in the next\n> version.\n>\n> ---\n>  include/libcamera/base/shared_fd.h | 10 ++++++++++\n>  src/libcamera/base/shared_fd.cpp   | 26 ++++++++++++++++++++++++++\n>  src/libcamera/framebuffer.cpp      |  2 +-\n>  3 files changed, 37 insertions(+), 1 deletion(-)\n>\n> diff --git a/include/libcamera/base/shared_fd.h b/include/libcamera/base/shared_fd.h\n> index 202192240110..e53a8b88601e 100644\n> --- a/include/libcamera/base/shared_fd.h\n> +++ b/include/libcamera/base/shared_fd.h\n> @@ -46,4 +46,14 @@ private:\n>  \tstd::shared_ptr<Descriptor> fd_;\n>  };\n>\n> +static inline bool operator==(const SharedFD &lhs, const SharedFD &rhs)\n> +{\n> +\treturn lhs.get() == rhs.get();\n> +}\n> +\n> +static inline bool operator!=(const SharedFD &lhs, const SharedFD &rhs)\n> +{\n> +\treturn !(lhs == rhs);\n> +}\n> +\n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/base/shared_fd.cpp b/src/libcamera/base/shared_fd.cpp\n> index bb35b448995d..bd2ab5aa25b7 100644\n> --- a/src/libcamera/base/shared_fd.cpp\n> +++ b/src/libcamera/base/shared_fd.cpp\n> @@ -214,6 +214,32 @@ SharedFD &SharedFD::operator=(SharedFD &&other)\n>   * instance is invalid\n>   */\n>\n> +/**\n> + * \\fn bool operator==(const SharedFD &lhs, const SharedFD &rhs)\n> + * \\brief Compare the owned file descriptors of two SharedFD for equality\n> + * \\param[in] lhs The first SharedFD\n> + * \\param[in] rhs The second SharedFD\n> + *\n> + * Two file descriptors are considered equal if they have the same numerical\n> + * value. File descriptors with different values that both reference the same\n> + * file (for instance obtained using dup()) are considered not equal.\n> + *\n> + * \\return True if the two file descriptors are equal, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn bool operator!=(const SharedFD &lhs, const SharedFD &rhs)\n> + * \\brief Compare the owned file descriptors of two SharedFD for equality\n> + * \\param[in] lhs The first SharedFD\n> + * \\param[in] rhs The second SharedFD\n> + *\n> + * Two file descriptors are considered equal if they have the same numerical\n> + * value. File descriptors with different values that both reference the same\n> + * file (for instance obtained using dup()) are considered not equal.\n> + *\n> + * \\return True if the two file descriptors are not equal, false otherwise\n> + */\n> +\n>  /**\n>   * \\brief Duplicate a SharedFD\n>   *\n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index ee93ba4da3d5..8857049ec33b 100644\n> --- a/src/libcamera/framebuffer.cpp\n> +++ b/src/libcamera/framebuffer.cpp\n> @@ -258,7 +258,7 @@ FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie)\n>  \t\t * Two different dmabuf file descriptors may still refer to the\n>  \t\t * same dmabuf instance. Check this using inodes.\n>  \t\t */\n> -\t\tif (plane.fd.fd() != planes_[0].fd.fd()) {\n> +\t\tif (plane.fd != planes_[0].fd) {\n>  \t\t\tif (!inode)\n>  \t\t\t\tinode = fileDescriptorInode(planes_[0].fd);\n>  \t\t\tif (fileDescriptorInode(plane.fd) != inode) {\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 67D42BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 22:09:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2692760720;\n\tTue, 30 Nov 2021 23:09:40 +0100 (CET)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A506605C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 23:09:38 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 7BD0D10000A;\n\tTue, 30 Nov 2021 22:09:37 +0000 (UTC)"],"Date":"Tue, 30 Nov 2021 23:10:29 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20211130221029.r2vennmbuqjnwjwy@uno.localdomain>","References":"<20211130033820.18235-21-laurent.pinchart@ideasonboard.com>\n\t<20211130102925.2141-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211130102925.2141-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4.1 20/22] libcamera: base:\n\tshared_fd: Add comparison operators","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>"}}]