[{"id":28558,"web_url":"https://patchwork.libcamera.org/comment/28558/","msgid":"<877ck16rwu.fsf@redhat.com>","date":"2024-01-22T20:21:05","subject":"Re: [PATCH 10/12] test: timer-thread: Destroy Object from correct\n\tthread context","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> The TimeoutHandler used in the test is destroyed from the main thread,\n> which is invalid for a thread-bound object bound to a different thread.\n> Fix it by destroying it with deleteLater().\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  test/timer-fail.cpp   | 16 +++++++++++-----\n>  test/timer-thread.cpp | 14 ++++++++++----\n>  2 files changed, 21 insertions(+), 9 deletions(-)\n>\n> diff --git a/test/timer-fail.cpp b/test/timer-fail.cpp\n> index e9a3b1b61bcb..b89c85f2ee72 100644\n> --- a/test/timer-fail.cpp\n> +++ b/test/timer-fail.cpp\n> @@ -54,7 +54,9 @@ protected:\n>  \tint init()\n>  \t{\n>  \t\tthread_.start();\n> -\t\ttimeout_.moveToThread(&thread_);\n> +\n> +\t\ttimeout_ = new TimeoutHandler();\n> +\t\ttimeout_->moveToThread(&thread_);\n>  \n>  \t\treturn TestPass;\n>  \t}\n> @@ -67,7 +69,7 @@ protected:\n>  \t\t * event dispatcher to make sure we don't succeed simply because\n>  \t\t * the event dispatcher hasn't noticed the timer restart.\n>  \t\t */\n> -\t\ttimeout_.start();\n> +\t\ttimeout_->start();\n>  \t\tthread_.eventDispatcher()->interrupt();\n>  \n>  \t\tthis_thread::sleep_for(chrono::milliseconds(200));\n> @@ -77,7 +79,7 @@ protected:\n>  \t\t * TestPass in the unexpected (usually known as \"fail\"), case,\n>  \t\t * and TestFail otherwise.\n>  \t\t */\n> -\t\tif (timeout_.timeout()) {\n> +\t\tif (timeout_->timeout()) {\n>  \t\t\tcout << \"Timer start from wrong thread succeeded unexpectedly\"\n>  \t\t\t     << endl;\n>  \t\t\treturn TestPass;\n> @@ -88,13 +90,17 @@ protected:\n>  \n>  \tvoid cleanup()\n>  \t{\n> -\t\t/* Must stop thread before destroying timeout. */\n> +\t\t/*\n> +\t\t * Object class instances must be destroyed from the thread\n> +\t\t * they live in.\n> +\t\t */\n> +\t\ttimeout_->deleteLater();\n>  \t\tthread_.exit(0);\n>  \t\tthread_.wait();\n>  \t}\n>  \n>  private:\n> -\tTimeoutHandler timeout_;\n> +\tTimeoutHandler *timeout_;\n>  \tThread thread_;\n>  };\n>  \n> diff --git a/test/timer-thread.cpp b/test/timer-thread.cpp\n> index 4caf4e33b2ba..8675e2480aa9 100644\n> --- a/test/timer-thread.cpp\n> +++ b/test/timer-thread.cpp\n> @@ -50,7 +50,9 @@ protected:\n>  \tint init()\n>  \t{\n>  \t\tthread_.start();\n> -\t\ttimeout_.moveToThread(&thread_);\n> +\n> +\t\ttimeout_ = new TimeoutHandler();\n> +\t\ttimeout_->moveToThread(&thread_);\n>  \n>  \t\treturn TestPass;\n>  \t}\n> @@ -63,7 +65,7 @@ protected:\n>  \t\t */\n>  \t\tthis_thread::sleep_for(chrono::milliseconds(200));\n>  \n> -\t\tif (!timeout_.timeout()) {\n> +\t\tif (!timeout_->timeout()) {\n>  \t\t\tcout << \"Timer expiration test failed\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -73,13 +75,17 @@ protected:\n>  \n>  \tvoid cleanup()\n>  \t{\n> -\t\t/* Must stop thread before destroying timeout. */\n> +\t\t/*\n> +\t\t * Object class instances must be destroyed from the thread\n> +\t\t * they live in.\n> +\t\t */\n> +\t\ttimeout_->deleteLater();\n>  \t\tthread_.exit(0);\n>  \t\tthread_.wait();\n>  \t}\n>  \n>  private:\n> -\tTimeoutHandler timeout_;\n> +\tTimeoutHandler *timeout_;\n>  \tThread thread_;\n>  };","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 813FCC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Jan 2024 20:21:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CEBAB62936;\n\tMon, 22 Jan 2024 21:21:12 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E64A62916\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jan 2024 21:21:11 +0100 (CET)","from mail-ed1-f69.google.com (mail-ed1-f69.google.com\n\t[209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-524-PO3qQx8HNha9oX2jVwmkRQ-1; Mon, 22 Jan 2024 15:21:09 -0500","by mail-ed1-f69.google.com with SMTP id\n\t4fb4d7f45d1cf-5597da35ebbso2290316a12.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jan 2024 12:21:08 -0800 (PST)","from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\tcb9-20020a0564020b6900b0055c33781c17sm1724752edb.75.2024.01.22.12.21.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 22 Jan 2024 12:21:05 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"AefqMwwS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1705954870;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=63ijnH6FomA5pdI78sItAj9dKQnesk9V+4puP6KZANQ=;\n\tb=AefqMwwSALYLRmTRBExpy/7hC8W7v1neEA6qWo4A4GiRijv3uwqo0sLpQ/lU186LWa0CRI\n\tOb7gA+X69kwip+0ifIxDucse97nmyHgBGBAu94cQiE7nRIbbnMpbraOX/cn/HZcEk6pXhl\n\tanNUWJmkmpIyem2OVWwyrWweXYusRhc=","X-MC-Unique":"PO3qQx8HNha9oX2jVwmkRQ-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1705954866; x=1706559666;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=63ijnH6FomA5pdI78sItAj9dKQnesk9V+4puP6KZANQ=;\n\tb=kQvwtn6HA6dSgzfAqBNsu6htBntJab8hyOTllgkTyGesiEUXddjoqkMP+LTmLOY+qk\n\te8JMZuGm1579NcDQ2WKKEfjqv9mFnvj2FvJAuXz63S0jI530vL4FwiAi8pbhAk9SR8Ry\n\tC/5blEB1fP1vqcQLwJNS7WAL9t/7wcet4wWdaaQN4QSbL2TLfqrsI6zs+usbcXKKJc1X\n\tar81OOKhoMhTmeM9aAWWvzx2WnINb6tTLXFSHFzkkcFygXvWknKAGNKVBPOFvEymhwdl\n\tTYbgiSHh0Y7uuX/ROkIn4PyWDMGI3CE7fzdHH6qpzv+Bmrlx6I64jDVgwbLkhmh1++FN\n\tm4HQ==","X-Gm-Message-State":"AOJu0Yw1gDSK7fT/0gZ4dzq++Sseo9UQIFt8k+AJKqxF/mMHKhgESdxT\n\tosFoqIUYlD3bj6FYBjL5do7/Mm/YmGxbw0+ER1UoB1eQB2zN5Kx0UAlUJN09Jw3Q6KuiryeT3TT\n\tuPrIwy+bVy8rDRkFZ+C5OhSjsMZQ39VfDs2h/IFa+Zuz6yeE306lU3KcOTS79Zp9SYMXYhkD8Hn\n\tEdl8AGaNU0cRdejONi94F7dDYuCpECvzXbSqkB/lro2I8/kiY9gpo16+o=","X-Received":["by 2002:aa7:d484:0:b0:55c:359c:599d with SMTP id\n\tb4-20020aa7d484000000b0055c359c599dmr273389edr.73.1705954866740; \n\tMon, 22 Jan 2024 12:21:06 -0800 (PST)","by 2002:aa7:d484:0:b0:55c:359c:599d with SMTP id\n\tb4-20020aa7d484000000b0055c359c599dmr273385edr.73.1705954866354; \n\tMon, 22 Jan 2024 12:21:06 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IF9r50pTXZflFA/ECXrn8EpH0ZnXrJzzn8a+f1S2EGR+1Y+ipQzM9pgJCrZssOl9mjAGYvkgw==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH 10/12] test: timer-thread: Destroy Object from correct\n\tthread context","In-Reply-To":"<20240121035948.4226-11-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Sun, 21 Jan 2024 05:59:46 +0200\")","References":"<20240121035948.4226-1-laurent.pinchart@ideasonboard.com>\n\t<20240121035948.4226-11-laurent.pinchart@ideasonboard.com>","Date":"Mon, 22 Jan 2024 21:21:05 +0100","Message-ID":"<877ck16rwu.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]