From patchwork Thu Oct 28 11:15:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 14400 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 8A845BF415 for ; Thu, 28 Oct 2021 11:14:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C576A600F9; Thu, 28 Oct 2021 13:14:47 +0200 (CEST) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06308600C0 for ; Thu, 28 Oct 2021 13:14:40 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 8FA7DFF802; Thu, 28 Oct 2021 11:14:39 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 13:15:15 +0200 Message-Id: <20211028111520.256612-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211028111520.256612-1-jacopo@jmondi.org> References: <20211028111520.256612-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/10] libcamera: request: Add support for fences 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" Prepare the Request::Private class to handle fences by providing a storage vector and interface functions to handle the number of pending and expired fences. The intended user of the interface is the PipelineHandler class Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/internal/request.h | 21 +++++++ src/libcamera/request.cpp | 89 +++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/request.h b/include/libcamera/internal/request.h index df0cc014067e..2be4874756de 100644 --- a/include/libcamera/internal/request.h +++ b/include/libcamera/internal/request.h @@ -7,8 +7,12 @@ #ifndef __LIBCAMERA_INTERNAL_REQUEST_H__ #define __LIBCAMERA_INTERNAL_REQUEST_H__ +#include + #include +#include + namespace libcamera { class Camera; @@ -24,9 +28,26 @@ public: Camera *camera() const { return camera_; } + unsigned int pendingFences() const { return pendingFences_; } + unsigned int expiredFences() const { return expiredFences_; } + + void reuse(); + + std::vector &fences() { return fences_; } + void addFence(Fence &&fence); + void clearFences(); + + void fenceExpired(); + void fenceCompleted(); + private: Camera *camera_; bool cancelled_; + + unsigned int pendingFences_ = 0; + unsigned int expiredFences_ = 0; + + std::vector fences_; }; } /* namespace libcamera */ diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 33fee1ac05ba..e88eee1fac36 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -63,6 +63,92 @@ Request::Private::~Private() * request hasn't been queued */ +/** + * \fn Request::Private::pendingFences() + * \brief Retrieve the number of pending fences + * + * A Fence is pending if has not yet been signalled or it has not expired yet. + * + * \return The number of pending fences + */ + +/** + * \fn Request::Private::expiredFences() + * \brief Retrieve the number of expired fences + * \return The number of expired fences + */ + +/** + * \brief Reset the request for reuse + */ +void Request::Private::reuse() +{ + cancelled_ = false; + + fences_.clear(); + pendingFences_ = 0; + expiredFences_ = 0; +} + +/** + * \fn Request::Private::fences() + * \brief Retrieve a reference to the vector of pending fences + * \return A reference to the vector of pending fences + */ + +/** + * \brief Move a Fence into the Request + * + * Move a Fence into the Request and increase the pending fences + * counter. The Fence is now stored into the Request and the original + * one passed in as parameter is reset. + * + * Once the Fence completes, either because it is signalled or because + * it has expired, the caller shall notify the Request about this by + * calling fenceCompleted() or fenceExpired(); + */ +void Request::Private::addFence(Fence &&fence) +{ + fences_.push_back(std::move(fence)); + pendingFences_++; +} + +/** + * \brief Release all Fences stored in the request + * + * Clear the vector of fences in the Request by releasing all of them. + * All Fences are closed and their file descriptors reset to 0. + */ +void Request::Private::clearFences() +{ + ASSERT(!pendingFences_); + fences_.clear(); +} + +/** + * \brief Notify that a Fence has been signalled + * + * Notify to the Request that a Fence has completed. This function decrease the + * number of pending Fences in the request. + */ +void Request::Private::fenceCompleted() +{ + pendingFences_--; +} + +/** + * \brief Notify that a Fence has expired + * + * Notify to the Request that a Fence has expired. This function decrease the + * number of pending Fences in the request and increase the number of expired + * ones. + */ +void Request::Private::fenceExpired() +{ + expiredFences_++; + pendingFences_--; +} + /** * \enum Request::Status * Request completion status @@ -158,10 +244,11 @@ void Request::reuse(ReuseFlag flags) sequence_ = 0; status_ = RequestPending; - _d()->cancelled_ = false; controls_->clear(); metadata_->clear(); + + _d()->reuse(); } /**