From patchwork Tue Nov 30 03:37:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14855 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 8DA6ABF415 for ; Tue, 30 Nov 2021 03:38:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 21AA3605B9; Tue, 30 Nov 2021 04:38:50 +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="V3zf7/s2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7FA0C604FC for ; Tue, 30 Nov 2021 04:38:48 +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 DE3248F0 for ; Tue, 30 Nov 2021 04:38:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1638243528; bh=G6Z/DeAZ6uWYI/Qoj53JWz5E2QZ7ejH0S2eFOUXkW0s=; h=From:To:Subject:Date:From; b=V3zf7/s2aMFSSbCpKotSjr1/JnhlU8+2DDd/JbVgk5BQMiGefcJPHpcpovEkBPX1j H/Sbv0UJNK0mcfKyjKmHHxqqCKgiznhemupjmemqJqEki4c6HqtFK0vqI61JoIVGQe 7XD5wuOvXRHPgjAZWUKzQFkGT9GjgnWN1nOgK/FQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 05:37:58 +0200 Message-Id: <20211130033820.18235-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 00/22] libcamera: Introduce UniqueFD 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" Hello, This patch series is a continuation of Hiro's work on the ScopedFD class ([1]). The class is a std::unique_ptr<>-like wrapper around file descriptors, which complements the existing shared-ownership FileDescriptor. Compared to v2, the main changes are a rename of ScopedFD to UniqueFD, and to match that, of FileDescriptor to SharedFD, as well as a new unit test. Compared to v3, review comments have been take into account, and five patches have been added: - Patch 11/22 fixes an fd leak - Patch 16/22 uses SharedFD in V4L2VideoDevice::open() - Patch 20/22 improves SharedFD with comparison operators - Patch 21/22 renames SharedFD::fd() to get() for consistency with UniqueFD - Patch 22/22 passes fds by rvalue reference to the UniqueFD constructor and reset() function As indicated in patch 22/22, if rvalue references are preferred, the patch will be squashed with 04/22. [1] https://patchwork.libcamera.org/project/libcamera/list/?series=2115 Hirokazu Honda (11): libcamera: base: Introduce UniqueFD libcamera: base: file_descriptor: Add constructor from UniqueFD libcamera: event_dispatcher_poll: Manage fd by UniqueFD libcamera: file: Manage fd by UniqueFD libcamera: ipc_unixsocket: Use UniqueFD for a file descriptor libcamera: process: Manage pipe fds by UniqueFD libcamera: media_device: Manage fd by UniqueFD libcamera: v4l2_device: Use UniqueFD for a file descriptor libcamera: v4l2_videodevice: Use fd for a file descriptor libcamera: pipeline: raspberrypi: DmaHeaps: Use UniqueFD for a file descriptor v4l2: v4l2_camera: Return int in getBufferFd() Laurent Pinchart (11): libcamera: Move compiler.h to base/ libcamera: Move file_descriptor.h to base/ libcamera: base: file_descriptor: Move inode() function to frame_buffer.cpp test: Add UniqueFD test libcamera: base: file_descriptor: Return UniqueFD from dup() libcamera: ipc_unixsocket: Fix file descriptor leak libcamera: v4l2_videodevice: Pass SharedFD to open() libcamera: base: Rename FileDescriptor to SharedFD libcamera: base: shared_fd: Add comparison operators libcamera: base: shared_fd: Rename fd() to get() libcamera: base: unique_fd: Pass rvalue reference to constructor and reset() include/libcamera/{ => base}/compiler.h | 0 .../libcamera/base/event_dispatcher_poll.h | 3 +- include/libcamera/base/file.h | 7 +- include/libcamera/base/meson.build | 3 + include/libcamera/base/shared_fd.h | 59 ++++ include/libcamera/base/unique_fd.h | 70 +++++ include/libcamera/file_descriptor.h | 49 --- include/libcamera/framebuffer.h | 5 +- include/libcamera/geometry.h | 2 +- .../libcamera/internal/ipa_data_serializer.h | 40 +-- include/libcamera/internal/ipc_pipe.h | 9 +- include/libcamera/internal/ipc_unixsocket.h | 7 +- include/libcamera/internal/media_device.h | 3 +- include/libcamera/internal/process.h | 4 +- include/libcamera/internal/v4l2_device.h | 9 +- include/libcamera/internal/v4l2_videodevice.h | 8 +- include/libcamera/ipa/core.mojom | 6 +- include/libcamera/ipa/raspberrypi.mojom | 2 +- include/libcamera/meson.build | 2 - src/android/camera_device.cpp | 2 +- src/cam/drm.cpp | 4 +- src/cam/image.cpp | 4 +- src/gstreamer/gstlibcameraallocator.cpp | 2 +- src/ipa/raspberrypi/raspberrypi.cpp | 6 +- src/libcamera/base/event_dispatcher_poll.cpp | 11 +- src/libcamera/base/file.cpp | 26 +- src/libcamera/base/meson.build | 2 + src/libcamera/base/shared_fd.cpp | 288 ++++++++++++++++++ src/libcamera/base/unique_fd.cpp | 129 ++++++++ src/libcamera/file_descriptor.cpp | 272 ----------------- src/libcamera/framebuffer.cpp | 36 ++- src/libcamera/ipa_data_serializer.cpp | 100 +++--- src/libcamera/ipc_pipe.cpp | 6 +- src/libcamera/ipc_pipe_unixsocket.cpp | 8 +- src/libcamera/ipc_unixsocket.cpp | 43 +-- src/libcamera/mapped_framebuffer.cpp | 4 +- src/libcamera/media_device.cpp | 36 +-- src/libcamera/meson.build | 1 - .../pipeline/raspberrypi/dma_heaps.cpp | 41 +-- .../pipeline/raspberrypi/dma_heaps.h | 10 +- .../pipeline/raspberrypi/raspberrypi.cpp | 13 +- src/libcamera/process.cpp | 16 +- src/libcamera/v4l2_device.cpp | 23 +- src/libcamera/v4l2_videodevice.cpp | 65 ++-- src/v4l2/v4l2_camera.cpp | 6 +- src/v4l2/v4l2_camera.h | 4 +- src/v4l2/v4l2_camera_proxy.cpp | 6 +- test/ipc/unixsocket.cpp | 14 +- test/ipc/unixsocket_ipc.cpp | 8 +- test/meson.build | 3 +- .../ipa_data_serializer_test.cpp | 14 +- test/{file-descriptor.cpp => shared-fd.cpp} | 86 +++--- test/unique-fd.cpp | 222 ++++++++++++++ .../module_ipa_proxy.cpp.tmpl | 2 +- .../module_ipa_proxy.h.tmpl | 2 +- .../module_ipa_proxy_worker.cpp.tmpl | 13 +- .../libcamera_templates/proxy_functions.tmpl | 2 +- .../libcamera_templates/serializer.tmpl | 22 +- .../generators/mojom_libcamera_generator.py | 6 +- 59 files changed, 1154 insertions(+), 692 deletions(-) rename include/libcamera/{ => base}/compiler.h (100%) create mode 100644 include/libcamera/base/shared_fd.h create mode 100644 include/libcamera/base/unique_fd.h delete mode 100644 include/libcamera/file_descriptor.h create mode 100644 src/libcamera/base/shared_fd.cpp create mode 100644 src/libcamera/base/unique_fd.cpp delete mode 100644 src/libcamera/file_descriptor.cpp rename test/{file-descriptor.cpp => shared-fd.cpp} (65%) create mode 100644 test/unique-fd.cpp base-commit: 8178e01b36d767e05d7bbb9dd1f752f7ede0db3d