From patchwork Sun Jan 21 03:59:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19426 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 84310C32BC for ; Sun, 21 Jan 2024 03:59:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 253F562945; Sun, 21 Jan 2024 04:59:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705809597; bh=ezRIQuCZBnWVllkKVhQA2PQQBoAV/G8PQmQ/Z/WIfGs=; 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=vUZuDwqpo7g+zhmfSf05JOpv3OIqN4nl/8oBh27lP45AoNXs7vvnxW7WHIzVqLvCM 82RlIHrvHxWJukUuc9Ch9dvuV5dY1sYW09pECkA+9dAtl23nh5bbiJGU/Pg73BMVfe HnLXaSUgXFVwUpS/rRfLbRIrFJNxTr724uH7B7irJDaWtLC1USAKUNeffrriGRnvdp IhAlMg8wREEjLgo8WvAK2amWIzKBjQQn2fSO5Wl2g8pKcOQqgqzB5cPy57BPtQubBd DjnOmTVoK7x7btdi24yAWKNXbD3x+21pHJZZtJG2xOsSkF5IvzQQQqynnAOxKK5ELS 7EG71x/658CGw== 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 A00946293E for ; Sun, 21 Jan 2024 04:59:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="c9s0JG50"; 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 8DD798D4; Sun, 21 Jan 2024 04:58:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705809520; bh=ezRIQuCZBnWVllkKVhQA2PQQBoAV/G8PQmQ/Z/WIfGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9s0JG50zOgsJ9VKKgzV83VYFtU1rRNDiMxqO5XYugRO6+4MXFNfQJZMHHxNCBgd4 9I2nT7X4jakbXYBXGfPtxqMfOZ6fiAzRykwhvD1lit2qTqAwS+WTpK2xW5+37oCeZS gV2+xWSg//DznIv0AuIT/nOGRUpSp9XF1o9z4qto= To: libcamera-devel@lists.libcamera.org Date: Sun, 21 Jan 2024 05:59:41 +0200 Message-ID: <20240121035948.4226-6-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 05/12] test: event-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 EventHandler 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/event-thread.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/test/event-thread.cpp b/test/event-thread.cpp index 88a8c07ef9f0..d6e5d27af185 100644 --- a/test/event-thread.cpp +++ b/test/event-thread.cpp @@ -85,10 +85,17 @@ private: class EventThreadTest : public Test { protected: + int init() + { + thread_.start(); + + handler_ = new EventHandler(); + + return TestPass; + } + int run() { - Thread thread; - thread.start(); /* * Fire the event notifier and then move the notifier to a @@ -98,23 +105,33 @@ protected: * different thread will correctly process already pending * events in the new thread. */ - EventHandler handler; - handler.notify(); - handler.moveToThread(&thread); + handler_->notify(); + handler_->moveToThread(&thread_); this_thread::sleep_for(chrono::milliseconds(100)); - /* Must stop thread before destroying the handler. */ - thread.exit(0); - thread.wait(); - - if (!handler.notified()) { + if (!handler_->notified()) { cout << "Thread event handling test failed" << endl; return TestFail; } return TestPass; } + + void cleanup() + { + /* + * Object class instances must be destroyed from the thread + * they live in. + */ + handler_->deleteLater(); + thread_.exit(0); + thread_.wait(); + } + +private: + EventHandler *handler_; + Thread thread_; }; TEST_REGISTER(EventThreadTest)