From 1df8091e631b72df8ecda105dae7934b54b1287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 7 Mar 2025 16:00:21 +0100 Subject: libcamera: v4l2_videodevice: `lastUsedCounter_` need not be atomic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `V4L2BufferCache` type is not thread-safe. Its `lastUsedCounter_` member is not used in contexts where its atomicity would matter. So it does not need to be have an atomic type. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/internal/v4l2_videodevice.h | 3 +-- src/libcamera/v4l2_videodevice.cpp | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index f021c2a0..ae6a76cb 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include #include @@ -158,7 +157,7 @@ private: std::vector planes_; }; - std::atomic lastUsedCounter_; + uint64_t lastUsedCounter_; std::vector cache_; /* \todo Expose the miss counter through an instrumentation API. */ unsigned int missCounter_; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index e241eb47..f5b3fa09 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -190,7 +190,7 @@ V4L2BufferCache::V4L2BufferCache(const std::vector> { for (const std::unique_ptr &buffer : buffers) cache_.emplace_back(true, - lastUsedCounter_.fetch_add(1, std::memory_order_acq_rel), + lastUsedCounter_++, *buffer.get()); } @@ -258,7 +258,7 @@ int V4L2BufferCache::get(const FrameBuffer &buffer) return -ENOENT; cache_[use] = Entry(false, - lastUsedCounter_.fetch_add(1, std::memory_order_acq_rel), + lastUsedCounter_++, buffer); return use; -- cgit v1.2.1