From patchwork Sun Jan 21 03:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19429 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 CE412C3243 for ; Sun, 21 Jan 2024 04:00:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9BE6A62916; Sun, 21 Jan 2024 05:00:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705809604; bh=1Ry5mE8qE3p3JgOCxvID4DWvwVQFWwR6qvm0EdZYFoA=; 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=KOB4wTB9tPZb8tkir24GoNClJOja4IiZmi4Ag+NesfLeK/ZFZCWdQkeCq2pdwzeqo pVWfdzTGj7TqoFAdyqng5zd3vSoSyB7WIzuHkK6nxiteD4C/NSNfmRFrH/zNIUbuun N9Ip6DesSKh1ts6LksjXuqL0YHFvVZt5sIm64+avwxmSHVWXI6ffGN9XDFMU4t7xA9 SEDF/DG2E21TMoK0GkxtYKqZS6EuLmdzyDvWtK66guV166T/npM96dt6r/l4Dr3SgM Bq88sjMuCqhOuPECtwCyGR8o4HHBtK43cNGvgq7+7fr/yzqU85YB3CTqHOymlMyRDt sdje7vTXN8qCQ== 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 8D36A6294C for ; Sun, 21 Jan 2024 04:59:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fM6IyA2E"; 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 7ED918D4; Sun, 21 Jan 2024 04:58:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705809524; bh=1Ry5mE8qE3p3JgOCxvID4DWvwVQFWwR6qvm0EdZYFoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fM6IyA2EhO+JmsY69T9HKYc4+zi7IDCUVLaPqUS8ai0yWvWW5iRxAMykVTxItTVZs Q63IaZ4/sK5dhTDMVnnQzkNfiGX13vUUri5g5qD+tvEZa2FcM+cI0p8b1RD5J3KKYr 49RSH5eFA0CZN6FuAMR+O981sCt+MVpdQRoXEJLI= To: libcamera-devel@lists.libcamera.org Date: Sun, 21 Jan 2024 05:59:44 +0200 Message-ID: <20240121035948.4226-9-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 08/12] test: signal-threads: Destroy Object from correct thread context 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 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_;