From patchwork Tue Nov 30 03:38:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14874 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 308D5C324F for ; Tue, 30 Nov 2021 03:39:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2D76605C5; Tue, 30 Nov 2021 04:39:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AwEdTUv7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 24ECC605B4 for ; Tue, 30 Nov 2021 04:38:58 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B358A11C5 for ; Tue, 30 Nov 2021 04:38:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1638243537; bh=coQj4WjDhPVcXGO++CaKss9us4nnKmA0FYDetl8KRgw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AwEdTUv7hdshLmmKHUpMD9C5XSZuI2M2euS3g0CzDJuWgOn5tCtjWsuczHDhsOmyl 0WIIMb7xuNseSDAZQBwaeyB1e/B/To0QZBoSH/oC+HKhFXgqWpvaPT07mP7r0OW66v pds7X6JUelo99c3EjLbrrKXLjD3y113U49tsUV3c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 05:38:18 +0200 Message-Id: <20211130033820.18235-21-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 Subject: [libcamera-devel] [PATCH v4 20/22] libcamera: base: shared_fd: Add comparison operators X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add == and != comparison operators between two SharedFD instances, and use them to replace manuel get() calls. Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda --- include/libcamera/base/shared_fd.h | 10 ++++++++++ src/libcamera/base/shared_fd.cpp | 26 ++++++++++++++++++++++++++ src/libcamera/framebuffer.cpp | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/libcamera/base/shared_fd.h b/include/libcamera/base/shared_fd.h index a786885ceb32..1dd51a7f046b 100644 --- a/include/libcamera/base/shared_fd.h +++ b/include/libcamera/base/shared_fd.h @@ -46,4 +46,14 @@ private: std::shared_ptr fd_; }; +static inline bool operator==(const SharedFD &lhs, const SharedFD &rhs) +{ + return lhs.get() == rhs.get(); +} + +static inline bool operator!=(const SharedFD &lhs, const SharedFD &rhs) +{ + return !(lhs == rhs); +} + } /* namespace libcamera */ diff --git a/src/libcamera/base/shared_fd.cpp b/src/libcamera/base/shared_fd.cpp index 05b6892f7e19..56dc579258c7 100644 --- a/src/libcamera/base/shared_fd.cpp +++ b/src/libcamera/base/shared_fd.cpp @@ -214,6 +214,32 @@ SharedFD &SharedFD::operator=(SharedFD &&other) * instance is invalid */ +/** + * \fn bool operator==(const SharedFD &lhs, const SharedFD &rhs) + * \brief Compare the owned file descriptors of two SharedFD for equality + * \param[in] lhs The first SharedFD + * \param[in] lhs The second SharedFD + * + * Two file descriptors are considered equal if they have the same numerical + * value. File descriptors with different values that both reference the same + * file (for instance obtained using dup()) are considered not equal. + * + * \return True if the two file descriptors are equal, false otherwise + */ + +/** + * \fn bool operator!=(const SharedFD &lhs, const SharedFD &rhs) + * \brief Compare the owned file descriptors of two SharedFD for equality + * \param[in] lhs The first SharedFD + * \param[in] lhs The second SharedFD + * + * Two file descriptors are considered equal if they have the same numerical + * value. File descriptors with different values that both reference the same + * file (for instance obtained using dup()) are considered not equal. + * + * \return True if the two file descriptors are not equal, false otherwise + */ + /** * \brief Duplicate a SharedFD * diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index f035e16859f8..f313566c5561 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -258,7 +258,7 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) * Two different dmabuf file descriptors may still refer to the * same dmabuf instance. Check this using inodes. */ - if (plane.fd.fd() != planes_[0].fd.fd()) { + if (plane.fd != planes_[0].fd) { if (!inode) inode = fileDescriptorInode(planes_[0].fd); if (fileDescriptorInode(plane.fd) != inode) {