From 4f8b1290e4a5be2670dff082722971d1a19fe378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 6 Feb 2025 15:09:37 +0100 Subject: [PATCH] libcamera: request: Store fence `EventNotifier` directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify a bit by storing the `EventNotifier` objects directly in the `std::map` instead of wrapping them in unique_ptr. An other advantage is that it removes one allocation per fence. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/internal/request.h | 2 +- src/libcamera/request.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/request.h b/include/libcamera/internal/request.h index 73e9bb5c..78cb99f3 100644 --- a/include/libcamera/internal/request.h +++ b/include/libcamera/internal/request.h @@ -59,7 +59,7 @@ private: bool prepared_ = false; std::unordered_set pending_; - std::map> notifiers_; + std::map notifiers_; std::unique_ptr timer_; }; diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 992d476e..60565f59 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -228,15 +228,12 @@ void Request::Private::prepare(std::chrono::milliseconds timeout) if (!fence) continue; - std::unique_ptr notifier = - std::make_unique(fence->fd().get(), - EventNotifier::Read); + auto [it, inserted] = notifiers_.try_emplace(buffer, fence->fd().get(), EventNotifier::Type::Read); + ASSERT(inserted); - notifier->activated.connect(this, [this, buffer] { - notifierActivated(buffer); - }); - - notifiers_[buffer] = std::move(notifier); + it->second.activated.connect(this, [this, buffer] { + notifierActivated(buffer); + }); } if (notifiers_.empty()) {