[PATCH v1] libcamera: request: Store fence `EventNotifier` directly
Barnabás Pőcze
barnabas.pocze at ideasonboard.com
Mon Mar 10 18:03:35 CET 2025
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 <barnabas.pocze at ideasonboard.com>
---
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 73e9bb5cc..78cb99f36 100644
--- a/include/libcamera/internal/request.h
+++ b/include/libcamera/internal/request.h
@@ -59,7 +59,7 @@ private:
bool prepared_ = false;
std::unordered_set<FrameBuffer *> pending_;
- std::map<FrameBuffer *, std::unique_ptr<EventNotifier>> notifiers_;
+ std::map<FrameBuffer *, EventNotifier> notifiers_;
std::unique_ptr<Timer> timer_;
};
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index b206ac132..6fa1801a0 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<EventNotifier> notifier =
- std::make_unique<EventNotifier>(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()) {
--
2.48.1
More information about the libcamera-devel
mailing list