From patchwork Sun Jan 21 03:59:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19424 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 0FD44C323E for ; Sun, 21 Jan 2024 03:59:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B76C76294B; Sun, 21 Jan 2024 04:59:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705809593; bh=4/6ICExn9z3UFsYl6U2WMNHXAzdh7EjXq0WmhmVa7xc=; 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=K5Z2hzgT84sAqHn+44SK9jkoja48Jp7WFCUjwoc9dDEKsiTlmH/A658tryS7ZWnwA FERUopbGIQzh8aeSASJaGaLv+UxpHkBNXf/js+RGtldeWgQ445IP9WKBb5UrtXwG30 QBkot7qKSAUTzmfbQR0hPkIDXcnTzwW/jq3w/ms/8rtMqrbKS4A8iSLVC9nRDI86RK Tojk1OA2kxraQylzr34hvF1i0KOzPHOskGD+kIgSc5om9e+f2aGttwtvfKaGh1ezF/ 3r/JkQVEsFBdGVlMvuNATBTYbLM4I1bsWXe985ATxu9sJu2k+/uDSjCrHOWmCyaHRM 0lATzuu0ozeow== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A173628E9 for ; Sun, 21 Jan 2024 04:59:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FIE6cEmd"; 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 D26D81574; Sun, 21 Jan 2024 04:58:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705809518; bh=4/6ICExn9z3UFsYl6U2WMNHXAzdh7EjXq0WmhmVa7xc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FIE6cEmdXLpQpjLMDF7ShALP9DJGwvr7J0Tj4xlPDS2L7r6uEBSsQ1Zs8g7o9MKNV rtDmIMritcRRXLIp6yoPy3kY18zj26Fqz/aMjeGYyL0Z+w8cQfqLD1pmfNQDSxZAUE hLhgc9EaGZdN1FIo5sFQIOfnvp07QJUF61wMz0j0= To: libcamera-devel@lists.libcamera.org Date: Sun, 21 Jan 2024 05:59:39 +0200 Message-ID: <20240121035948.4226-4-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 03/12] test: object-delete: Test deferred delete just before thread stops 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" The Object::deleterLater() function is expected to not race with stopping the thread the object is bound to. Add a test for this. The test currently fails, demonstrating a bug in libcamera. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- test/object-delete.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/test/object-delete.cpp b/test/object-delete.cpp index eabefe935974..80b7dc41cd37 100644 --- a/test/object-delete.cpp +++ b/test/object-delete.cpp @@ -33,10 +33,10 @@ public: unsigned int *deleteCount_; }; -class NewThread : public Thread +class DeleterThread : public Thread { public: - NewThread(Object *obj) + DeleterThread(Object *obj) : object_(obj) { } @@ -63,9 +63,9 @@ protected: unsigned int count = 0; TestObject *obj = new TestObject(&count); - NewThread thread(obj); - thread.start(); - thread.wait(); + DeleterThread delThread(obj); + delThread.start(); + delThread.wait(); Thread::current()->dispatchMessages(Message::Type::DeferredDelete); @@ -89,6 +89,26 @@ protected: return TestFail; } + /* + * Test that deleteLater() works properly when called just + * before the object's thread exits. + */ + Thread boundThread; + boundThread.start(); + + count = 0; + obj = new TestObject(&count); + obj->moveToThread(&boundThread); + + obj->deleteLater(); + boundThread.exit(); + boundThread.wait(); + + if (count != 1) { + cout << "Object deletion right before thread exit failed (" << count << ")" << endl; + return TestFail; + } + return TestPass; } };