From patchwork Mon Nov 30 17:17:44 2026 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: 29112 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 06F88C3300 for ; Mon, 30 Nov 2026 17:17:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 725E26AA45; Mon, 30 Nov 2026 18:17:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="e45rSOqh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E11A6AA45 for ; Mon, 30 Nov 2026 18:17:50 +0100 (CET) Received: from pb-laptop.local (185.182.215.119.nat.pool.zt.hu [185.182.215.119]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A7654DC for ; Mon, 30 Nov 2026 18:15:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796058912; bh=ATDT/Calh8QVor+0UGcB4QzW4x5TAyYKY2WXdN05loo=; h=From:To:Subject:Date:From; b=e45rSOqh9zF9Dv7EFhdfugKqWiQ5AR0ia0qpyEDztCrPMOj/ulhd5xhB4DD5sOVOn CJDbxnhDwKNuTeI7bQgpE70baqV9IeZbDhtLbHxyO/NGK3ybJsiAJ1GkuPjRiiLd4J xXydrgq890ifSzXeZYu700PmaMrnsBzCnkMDzr7Q= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 1/2] libcamera: base: thread: removeMessages(): Avoid vector Date: Mon, 30 Nov 2026 18:17:44 +0100 Message-ID: <20261130171745.285537-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.56.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 Since the messages of a thread are contained in an `std::list`, use an `std::list` instead of an `std::vector` to collect the messages that need to be removed. By using `splice()`, this avoids any dynamic allocation. Note that this change does not cause issues in `dispatchMessages()` because before a message is dispatched, the pointer is moved-from the list, leaving it as nullptr. This means that the a message that is being dispatched is never erased, and thus the dispatching will continue as expected. Signed-off-by: Barnabás Pőcze --- src/libcamera/base/thread.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index b204355a58..d62a99f7da 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -586,24 +586,22 @@ void Thread::removeMessages(Object *receiver) if (!receiver->pendingMessages_) return; - std::vector> toDelete; - for (std::unique_ptr &msg : data_->messages_.list_) { - if (!msg) - continue; - if (msg->receiver_ != receiver) - continue; + std::list> toDelete; + for (auto it = data_->messages_.list_.begin(); it != data_->messages_.list_.end();) { + std::unique_ptr &msg = *it; /* * Move the message to the pending deletion list to delete it - * after releasing the lock. The messages list element will - * contain a null pointer, and will be removed when dispatching - * messages. + * after releasing the lock. */ - toDelete.push_back(std::move(msg)); - receiver->pendingMessages_--; + if (msg && msg->receiver_ == receiver) + toDelete.splice(toDelete.end(), data_->messages_.list_, it++); + else + ++it; } - ASSERT(!receiver->pendingMessages_); + ASSERT(receiver->pendingMessages_ == toDelete.size()); + receiver->pendingMessages_ = 0; locker.unlock(); toDelete.clear();