From patchwork Tue Jan 23 01:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19456 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 0ECF2C323E for ; Tue, 23 Jan 2024 01:13:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 927316296F; Tue, 23 Jan 2024 02:13:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NyVlstF3"; 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 D30F862962 for ; Tue, 23 Jan 2024 02:12:56 +0100 (CET) Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7BED5E4; Tue, 23 Jan 2024 02:11:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705972303; bh=5yuWptYz8PW21sw9SNhY5AR3DffrUrhkhXBqzoNDBu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyVlstF3lqFtspZNrpjr38V9h0SoIOORwioCa3GnmzqMKnMP8MbPP73uR3tXOoGjc 8MZvYjIkJuMSf2bPm0XoUB5zHAUx3cIxoEhPlG8KPqfb1TNsQHBfuHcyE1Hp9If2Qh OEyo9KsM2v8KPlHmoVRHRmCy3SckQ70SgM6pITL0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 08/12] test: signal-threads: Destroy Object from correct thread context Date: Tue, 23 Jan 2024 03:12:45 +0200 Message-ID: <20240123011249.22716-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123011249.22716-1-laurent.pinchart@ideasonboard.com> References: <20240123011249.22716-1-laurent.pinchart@ideasonboard.com> 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 SignalReceiver used in the test is destroyed from the main thread, which is invalid for a thread-bound object bound to a different thread. Fix it by destroying it with deleteLater(). Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- test/signal-threads.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/signal-threads.cpp b/test/signal-threads.cpp index 8c550eb014d8..8c212b6f9ade 100644 --- a/test/signal-threads.cpp +++ b/test/signal-threads.cpp @@ -59,15 +59,20 @@ private: class SignalThreadsTest : public Test { protected: + int init() + { + receiver_ = new SignalReceiver(); + signal_.connect(receiver_, &SignalReceiver::slot); + + return TestPass; + } + int run() { - SignalReceiver receiver; - signal_.connect(&receiver, &SignalReceiver::slot); - /* Test that a signal is received in the main thread. */ signal_.emit(0); - switch (receiver.status()) { + switch (receiver_->status()) { case SignalReceiver::NoSignal: cout << "No signal received for direct connection" << endl; return TestFail; @@ -83,8 +88,8 @@ protected: * Move the object to a thread and verify that the signal is * correctly delivered, with the correct data. */ - receiver.reset(); - receiver.moveToThread(&thread_); + receiver_->reset(); + receiver_->moveToThread(&thread_); thread_.start(); @@ -92,7 +97,7 @@ protected: this_thread::sleep_for(chrono::milliseconds(100)); - switch (receiver.status()) { + switch (receiver_->status()) { case SignalReceiver::NoSignal: cout << "No signal received for message connection" << endl; return TestFail; @@ -104,7 +109,7 @@ protected: break; } - if (receiver.value() != 42) { + if (receiver_->value() != 42) { cout << "Signal received with incorrect value" << endl; return TestFail; } @@ -114,11 +119,13 @@ protected: void cleanup() { + receiver_->deleteLater(); thread_.exit(0); thread_.wait(); } private: + SignalReceiver *receiver_; Thread thread_; Signal signal_;