From patchwork Fri Jul 1 08:45:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16498 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 34159BD808 for ; Fri, 1 Jul 2022 08:45:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E797656A0; Fri, 1 Jul 2022 10:45:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656665149; bh=eCXWxXuGWl5r0HMuik1XEkAxHOfVyvYcsHvaM+5SdA8=; 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=VtovqRHEcuk4ESMfuviee5cLgHvkOFbMXGgFwu+O+7IxbPcNarytq7dNWVK2130uA wWe/nwahd1gGESfxrq2LF/w7DTXCNH9dtOCulZutrbf0JtGMTAzmSmedCViX9NPTX7 8B5txjtSkTxlC2RRC7ESCf7wqfSEcLfLQOT4hSr4PjNlsZyXJxG1hnTCCu2/7+f0la x93+lh6DGbGEHwZnG5D14ZieLwJ/x3P653nDXCu5FPxWL6zVDARESz30B31vcF76Wi bV8pUR4fPqfGfn0YiWXm0/h+K6cxwPvp+z1J/lmO5bGsiz+pjMDKMzjH40sOFb7Lhr PlxFqGbnUZUcA== 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 85ECA65654 for ; Fri, 1 Jul 2022 10:45:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ckX+jhBv"; 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 02C8B6D1; Fri, 1 Jul 2022 10:45:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656665143; bh=eCXWxXuGWl5r0HMuik1XEkAxHOfVyvYcsHvaM+5SdA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckX+jhBvtLeNHwfUAHxwqfRi/HxivTisDLLD2PMceSHQwRGOZtW8p1ulPYT/qlgcv Ju2Ke3mG6Fa2siAQBHuwb7KBe6Ubx/+9v3Sk2vP4j+hBgQC4wE96kbF2uv1P86DGvK 3FurkPDYAFeggwJnxMb4lU+pgafTfNHXuIE9dcto= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 1 Jul 2022 11:45:10 +0300 Message-Id: <20220701084521.31831-7-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220701084521.31831-1-tomi.valkeinen@ideasonboard.com> References: <20220701084521.31831-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 06/17] 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 ad47271d..51a890c8 100644 --- a/src/py/libcamera/py_camera_manager.cpp +++ b/src/py/libcamera/py_camera_manager.cpp @@ -27,25 +27,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() @@ -93,7 +85,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. @@ -106,7 +98,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_;