[{"id":21410,"web_url":"https://patchwork.libcamera.org/comment/21410/","msgid":"<CAO5uPHOzs+WuNVGaBnGdGD3kBqMd6SppJN91TaWUQ0t8DaB5tA@mail.gmail.com>","date":"2021-11-30T05:27:02","subject":"Re: [libcamera-devel] [PATCH v4 20/22] libcamera: base: shared_fd:\n\tAdd comparison operators","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"Hi Laurent, thank you for the patch.\n\nOn Tue, Nov 30, 2021 at 12:39 PM Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\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> ---\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 a786885ceb32..1dd51a7f046b 100644\n> --- a/include/libcamera/base/shared_fd.h\n> +++ b/include/libcamera/base/shared_fd.h\n> @@ -46,4 +46,14 @@ private:\n>         std::shared_ptr<Descriptor> fd_;\n>  };\n>\n> +static inline bool operator==(const SharedFD &lhs, const SharedFD &rhs)\n> +{\n> +       return lhs.get() == rhs.get();\n> +}\n> +\n> +static inline bool operator!=(const SharedFD &lhs, const SharedFD &rhs)\n> +{\n> +       return !(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 05b6892f7e19..56dc579258c7 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] lhs The second SharedFD\n\nrhs\n\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] lhs The second SharedFD\n\nrhs.\n\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\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 f035e16859f8..f313566c5561 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>                  * Two different dmabuf file descriptors may still refer to the\n>                  * same dmabuf instance. Check this using inodes.\n>                  */\n> -               if (plane.fd.fd() != planes_[0].fd.fd()) {\n> +               if (plane.fd != planes_[0].fd) {\n>                         if (!inode)\n>                                 inode = fileDescriptorInode(planes_[0].fd);\n>                         if (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 2F944BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 05:27:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D4AE0605B4;\n\tTue, 30 Nov 2021 06:27:13 +0100 (CET)","from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com\n\t[IPv6:2a00:1450:4864:20::52b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D690D604FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 06:27:12 +0100 (CET)","by mail-ed1-x52b.google.com with SMTP id t5so82021571edd.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Nov 2021 21:27:12 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"BBVW0Cpf\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=hPiosXqmCmXA24gMUzM+l8kTOcexrGN7HrwncWrJ3no=;\n\tb=BBVW0Cpf97OeKMTj09iTePdQK9w9eq23rldVe79rjtFyp3VU+N7anxpd+cvyqByFdq\n\t2oy1VwrXAmIFpSRZh/SnM18hivpVhTZ/oqvF0/0xrtozEZq02csxZNxF/D9VXfN/pDCO\n\tWI/hiQecgWlzaenXxYJ77JZietrJK1pn5zj+0=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=hPiosXqmCmXA24gMUzM+l8kTOcexrGN7HrwncWrJ3no=;\n\tb=KvIXrwh248KpNgR2lOs1R1wUlWLTJNyUhY0EkwvhLHx1b1vVqephJyKSWU0S4lpV2l\n\tBX4c/+P7SpApMu3YXyK0o910U/W9cBzU1z58dPGiqFoj9WJHsOAn2YS3WZcxa0HOXhQp\n\tkKePpEEuaONqGLBb11Ji/TiUW2iYoRMpcO8d5kcmAakc1boluF4+VrosaDegEiHGxU0R\n\toO184tLTCIPWAXdlYtELLIk3tyBsPf+1cI9BTAikcs2R7vRoevH+WdYj86htZi0pREOX\n\tRbZsx75tQ+LOl4MLh3G0OVp2D/qnV4jDRIYooDI0wF8Sy0G8PCUGDhzBx+ZGoOUpPeWy\n\thy9w==","X-Gm-Message-State":"AOAM530XY8r6Yfd/9fAodZ2NdoH0P3Jt0+jQg2a1cc4GNLvcnn7/H7fV\n\tCTmDSh32a9TdGksWSXjJnBhmir9dR+0yl65ppGZ8Pw==","X-Google-Smtp-Source":"ABdhPJwZn8Fd4MUtz9ElFiIahU4fcfzLktwDOsuqUV1Yfs3J0cshmhP9PEsG7n4NxwVtNxCXT4mv7g9LoogdDtx52sY=","X-Received":"by 2002:a05:6402:60c:: with SMTP id\n\tn12mr81989551edv.17.1638250032491; \n\tMon, 29 Nov 2021 21:27:12 -0800 (PST)","MIME-Version":"1.0","References":"<20211130033820.18235-1-laurent.pinchart@ideasonboard.com>\n\t<20211130033820.18235-21-laurent.pinchart@ideasonboard.com>","In-Reply-To":"<20211130033820.18235-21-laurent.pinchart@ideasonboard.com>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Tue, 30 Nov 2021 14:27:02 +0900","Message-ID":"<CAO5uPHOzs+WuNVGaBnGdGD3kBqMd6SppJN91TaWUQ0t8DaB5tA@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v4 20/22] libcamera: base: shared_fd:\n\tAdd 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>"}},{"id":21423,"web_url":"https://patchwork.libcamera.org/comment/21423/","msgid":"<20211130080915.akkh5tkh5nzzlrio@uno.localdomain>","date":"2021-11-30T08:09:15","subject":"Re: [libcamera-devel] [PATCH v4 20/22] libcamera: base: shared_fd:\n\tAdd 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 05:38:18AM +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\nThis should prbably go after s/SharedFD::fd()/SharedFD::get()/\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 a786885ceb32..1dd51a7f046b 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 05b6892f7e19..56dc579258c7 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] lhs The second SharedFD\n\nrhs\n\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] lhs The second SharedFD\n\nhere too\n\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 f035e16859f8..f313566c5561 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 82D97BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 08:08:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D880B605B4;\n\tTue, 30 Nov 2021 09:08:24 +0100 (CET)","from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C94F360230\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 09:08:23 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 4A42A240007;\n\tTue, 30 Nov 2021 08:08:22 +0000 (UTC)"],"Date":"Tue, 30 Nov 2021 09:09:15 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20211130080915.akkh5tkh5nzzlrio@uno.localdomain>","References":"<20211130033820.18235-1-laurent.pinchart@ideasonboard.com>\n\t<20211130033820.18235-21-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211130033820.18235-21-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 20/22] libcamera: base: shared_fd:\n\tAdd 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>"}}]