From patchwork Fri Aug 19 11:16:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 17178 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 01ED0C327D for ; Fri, 19 Aug 2022 11:16:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AB17261FCF; Fri, 19 Aug 2022 13:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660907796; bh=pIBSw2MG0xHoUVahGKD6tsWMWqXwvmJx/AUNp1RZles=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CCWbfvh5Ks0unQpy7cqzjy+RSKf68g0/7WEvgfx0bQg5SMTooFL0nICMbqaUrPWwH SCOTvsQ0LcpjJMoEX9lhaYK1kBZgZq8/Sai02BhwBSCjm3jV0316TB4WYk7f508wOm v4Hd0mFgF8WTlMdaG1vEBONWBCzVYs78G/J1UVrtBCI5Sr828NOuEEtik6r1ic/a/U DcHnpb+D2KAhiuUszAo/zvn/rdDZvMj9pzI/FHScVSuI22vDiKut/2fntFYm9CTm/4 E7boN0EUkb5GkGEmcoKDZJxZrhIPZ+E2KmhqM3s4g4PgRkJEL7l1PvN2G4CCsnx3LT JMBQp5cJP31/Q== 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 B767A61FA4 for ; Fri, 19 Aug 2022 13:16:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VWssCl9n"; dkim-atps=neutral Received: from deskari.lan (91-158-154-79.elisa-laajakaista.fi [91.158.154.79]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 30B25D51; Fri, 19 Aug 2022 13:16:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660907791; bh=pIBSw2MG0xHoUVahGKD6tsWMWqXwvmJx/AUNp1RZles=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VWssCl9nVTpp0syJYi/JOn/tbg3y++wQVjhGMejdInV41PAmwOjXKFg2/lnvKUIzj LG+5Rjkyv90CEQ89QDIF9KzAFmKKywNc3WRF937iIxonqXKu1xdwp/Nd274fuHWfGL EY/Bxy+L2F5Cv/qRBHjattTQQtiLVGJqhccp1w6Y= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 19 Aug 2022 14:16:12 +0300 Message-Id: <20220819111615.39814-4-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819111615.39814-1-tomi.valkeinen@ideasonboard.com> References: <20220819111615.39814-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/6] py: Use 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: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use UniqueFD to automate the eventfd lifetime management. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/py_camera_manager.cpp | 16 ++++------------ src/py/libcamera/py_camera_manager.h | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/py/libcamera/py_camera_manager.cpp b/src/py/libcamera/py_camera_manager.cpp index 228fb212..18fdb623 100644 --- a/src/py/libcamera/py_camera_manager.cpp +++ b/src/py/libcamera/py_camera_manager.cpp @@ -29,25 +29,17 @@ PyCameraManager::PyCameraManager() throw std::system_error(errno, std::generic_category(), "Failed to create eventfd"); - eventFd_ = fd; + eventFd_ = UniqueFD(fd); int ret = cameraManager_->start(); - if (ret) { - close(fd); - eventFd_ = -1; + if (ret) throw std::system_error(-ret, std::generic_category(), "Failed to start CameraManager"); - } } PyCameraManager::~PyCameraManager() { LOG(Python, Debug) << "~PyCameraManager()"; - - if (eventFd_ != -1) { - close(eventFd_); - eventFd_ = -1; - } } py::list PyCameraManager::cameras() @@ -95,7 +87,7 @@ void PyCameraManager::writeFd() { uint64_t v = 1; - size_t s = write(eventFd_, &v, 8); + size_t s = write(eventFd_.get(), &v, 8); /* * We should never fail, and have no simple means to manage the error, * so let's log a fatal error. @@ -108,7 +100,7 @@ void PyCameraManager::readFd() { uint8_t buf[8]; - if (read(eventFd_, buf, 8) != 8) + if (read(eventFd_.get(), buf, 8) != 8) throw std::system_error(errno, std::generic_category()); } diff --git a/src/py/libcamera/py_camera_manager.h b/src/py/libcamera/py_camera_manager.h index 9c15f814..710163e8 100644 --- a/src/py/libcamera/py_camera_manager.h +++ b/src/py/libcamera/py_camera_manager.h @@ -24,7 +24,7 @@ public: static const std::string &version() { return CameraManager::version(); } - int eventFd() const { return eventFd_; } + int eventFd() const { return eventFd_.get(); } std::vector getReadyRequests(); @@ -33,7 +33,7 @@ public: private: std::unique_ptr cameraManager_; - int eventFd_ = -1; + UniqueFD eventFd_; std::mutex completedRequestsMutex_; std::vector completedRequests_;