From patchwork Sun Jan 21 03:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19431 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 EA8C2C32BF for ; Sun, 21 Jan 2024 04:00:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 19E3C6294B; Sun, 21 Jan 2024 05:00:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705809606; bh=+e/hHPQCKT9nxgeE3fXUKLUmAWXegOJC3OWkWcvvDI0=; 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=JyNy39FTP6z8hcmw3HhbSKYbPD6oC6gEBnRMdW8Lxhh2vueZjFCszr+gjpbD+OiY0 oMqCP2Ym3xy0JAWUzBZW1YnHGE4e1K51z+JXubBnOGMcJ4psJPukshN8uvt+rg8VF9 k0Ykgdlzobxggb3W55p+d1qGKng7Dy8JNbeO67PYh/m7/PHU9kEuQ7oHx8CePTRPR4 c84HfVx8HdkdKIS1J9DPdhTrcVZSKh0vtrUmbWFDeacRyp6hki0/T9e1Su3DdWh1b7 +cfbwIJmZhMmUZ2ELZHyvgD52G1TqNhxz7+TswZGaKvxMmwmMsqvkD52E0X/Znhcgo 2Pchs2XBKyQsQ== 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 2AB9B62957 for ; Sun, 21 Jan 2024 04:59:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MLma6vBW"; 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 24D938D4; Sun, 21 Jan 2024 04:58:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705809527; bh=+e/hHPQCKT9nxgeE3fXUKLUmAWXegOJC3OWkWcvvDI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MLma6vBWxs0qR9co/qZ2GgswuB8OMAfk9ZdD2gRDX6cCf6lW160FhY0Y3dRt+VCGd 0ndfMPzD0AuGLzaItTz0MxUrjl4YbmEjUqf7Cmse9clE5Snqm6px82ltTQVu74Xcb4 wojltPonRUG38ZXM0oFhrj3uUIbVNJfiHytZCdWs= To: libcamera-devel@lists.libcamera.org Date: Sun, 21 Jan 2024 05:59:46 +0200 Message-ID: <20240121035948.4226-11-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 10/12] test: timer-thread: 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 TimeoutHandler 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/timer-fail.cpp | 16 +++++++++++----- test/timer-thread.cpp | 14 ++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/timer-fail.cpp b/test/timer-fail.cpp index e9a3b1b61bcb..b89c85f2ee72 100644 --- a/test/timer-fail.cpp +++ b/test/timer-fail.cpp @@ -54,7 +54,9 @@ protected: int init() { thread_.start(); - timeout_.moveToThread(&thread_); + + timeout_ = new TimeoutHandler(); + timeout_->moveToThread(&thread_); return TestPass; } @@ -67,7 +69,7 @@ protected: * event dispatcher to make sure we don't succeed simply because * the event dispatcher hasn't noticed the timer restart. */ - timeout_.start(); + timeout_->start(); thread_.eventDispatcher()->interrupt(); this_thread::sleep_for(chrono::milliseconds(200)); @@ -77,7 +79,7 @@ protected: * TestPass in the unexpected (usually known as "fail"), case, * and TestFail otherwise. */ - if (timeout_.timeout()) { + if (timeout_->timeout()) { cout << "Timer start from wrong thread succeeded unexpectedly" << endl; return TestPass; @@ -88,13 +90,17 @@ protected: void cleanup() { - /* Must stop thread before destroying timeout. */ + /* + * Object class instances must be destroyed from the thread + * they live in. + */ + timeout_->deleteLater(); thread_.exit(0); thread_.wait(); } private: - TimeoutHandler timeout_; + TimeoutHandler *timeout_; Thread thread_; }; diff --git a/test/timer-thread.cpp b/test/timer-thread.cpp index 4caf4e33b2ba..8675e2480aa9 100644 --- a/test/timer-thread.cpp +++ b/test/timer-thread.cpp @@ -50,7 +50,9 @@ protected: int init() { thread_.start(); - timeout_.moveToThread(&thread_); + + timeout_ = new TimeoutHandler(); + timeout_->moveToThread(&thread_); return TestPass; } @@ -63,7 +65,7 @@ protected: */ this_thread::sleep_for(chrono::milliseconds(200)); - if (!timeout_.timeout()) { + if (!timeout_->timeout()) { cout << "Timer expiration test failed" << endl; return TestFail; } @@ -73,13 +75,17 @@ protected: void cleanup() { - /* Must stop thread before destroying timeout. */ + /* + * Object class instances must be destroyed from the thread + * they live in. + */ + timeout_->deleteLater(); thread_.exit(0); thread_.wait(); } private: - TimeoutHandler timeout_; + TimeoutHandler *timeout_; Thread thread_; };