From patchwork Sun Jan 21 03:59:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19425 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 C9BC9C3243 for ; Sun, 21 Jan 2024 03:59:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6F2D16293E; Sun, 21 Jan 2024 04:59:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705809596; bh=gqUGYcK7brqQTRQ3ldW7HRkE0TmtK5kwwdbwRLBWFxc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NPNjqHYTlcueuaDWYvrgfgo7aotbXTa85qrhV1hTjIrE6/gtT45SSnUQw36jjB4z8 5241tGLfPZHD7Qy9YKPgb03zsblCFnGHt4AnNYse08A0peIaXlAXXTvHQ06cjseCbT 8rJLObPTLzghaDQbVxl7c7ROtZu56YkvoAshpliaV2odMoR03aHD+DkexMMvzMeOwF N6WeXAR6RmKLJ32wKfs+7cann4ThuAiycPfDeYogaX7OPGZAcyY2CjN0mdNF0WlXvD 5kshya9n3YHl7+hQ9qVBAo4tDF+ECynqoF28In0mTk2v94vC8pNX+GerJB6rHMALvx 8YN4qFAlLcN1Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 52C5D62947 for ; Sun, 21 Jan 2024 04:59:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LDgqOCaa"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4066B138B; Sun, 21 Jan 2024 04:58:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705809519; bh=gqUGYcK7brqQTRQ3ldW7HRkE0TmtK5kwwdbwRLBWFxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LDgqOCaaJ0bKmk4XhjWG0/VHdcZm6diG/5v/DNK7GMKBS56aMA1/zc9+jDvZMiwy3 ISzcBqMDCgO/T45TGAU8WygrHm393zkMP0KCvRJKcsA1L7A1cdHAu5kDCJxvbYtE9H IWvD4FyxD73rLWSiKrPePgh5UBlKBKC2vUKdBYaw= To: libcamera-devel@lists.libcamera.org Date: Sun, 21 Jan 2024 05:59:40 +0200 Message-ID: <20240121035948.4226-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240121035948.4226-1-laurent.pinchart@ideasonboard.com> References: <20240121035948.4226-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/12] libcamera: thread: Ensure deferred deletion of all objects before stopping 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Objects can be scheduled for deletion with Object::deleteLater(), which queues a deferred deletion to the thread's event loop. As the deleteLater() function is meant to be called from a different thread, this may race with thread termination, and deferred deletions queued just before calling Thread::exit() may not be processed by the event loop. Make sure they get processed when finishing the thread, before stopping. This fixes a failure in the object-delete unit test. Signed-off-by: Laurent Pinchart --- src/libcamera/base/thread.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index 75693c92a0b1..4ac72036aa69 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -371,6 +371,12 @@ void Thread::run() void Thread::finishThread() { + /* + * Objects may have been scheduled for deletion right before the thread + * exited. Ensure they get deleted now, before the thread stops. + */ + dispatchMessages(Message::Type::DeferredDelete); + data_->mutex_.lock(); data_->running_ = false; data_->mutex_.unlock();