From patchwork Mon Mar 10 17:03:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22946 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 30301C32F1 for ; Mon, 10 Mar 2025 17:03:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2753687FA; Mon, 10 Mar 2025 18:03:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SzGFI+nB"; dkim-atps=neutral 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 F36B7687F0 for ; Mon, 10 Mar 2025 18:03:33 +0100 (CET) Received: from pb-laptop.local (185.221.143.221.nat.pool.zt.hu [185.221.143.221]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 489CA227 for ; Mon, 10 Mar 2025 18:01:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741626117; bh=u2Km0sfP+5a7CydMFT5g/+2GpinsHbRIKaubxO57OYQ=; h=From:To:Subject:Date:From; b=SzGFI+nB0MKu8rAPITK55oB0pH2bEnBfIp1mVlpYFhS1evDcvqhF/DSiiai3y3C4N t2YuNxjs+v2BJXGfTmwtzgep+Q2lG9Xp6x1btIw7qIfJWA7iM6WQE6k2Y7XCbqp47+ 846w+gE4W808ObSJ/Ny1v8nqXWoFituMym1VeQFk= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1] libcamera: v4l2_videodevice: `lastUsedCounter_` need not be atomic Date: Mon, 10 Mar 2025 18:03:26 +0100 Message-ID: <20250310170326.185273-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 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" 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 Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 2 +- src/libcamera/v4l2_videodevice.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index f021c2a01..e52b50c67 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -158,7 +158,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 e241eb47b..f5b3fa09d 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;