From f8d2f17a3db5ac490d7b505253a98d6795c2b630 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 29 Nov 2021 21:01:55 +0200 Subject: libcamera: base: shared_fd: Add comparison operators 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 Reviewed-by: Jacopo Mondi --- src/libcamera/base/shared_fd.cpp | 26 ++++++++++++++++++++++++++ src/libcamera/framebuffer.cpp | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libcamera/base/shared_fd.cpp b/src/libcamera/base/shared_fd.cpp index bb35b448..bd2ab5aa 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] rhs 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] rhs 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 ee93ba4d..8857049e 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) { -- cgit v1.2.1