summaryrefslogtreecommitdiff
path: root/test/timer-fail.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-01-19 03:43:55 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-01-25 02:39:20 +0200
commitfdcea5ad7996f65848006e4df8ab75e20dbc0461 (patch)
tree45e70ccef9057d70701824b32005e763955cc5cf /test/timer-fail.cpp
parent4f76beae8612f02e086e96d79447b7e8984c8821 (diff)
test: timer-thread: Destroy Object from correct thread context
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Diffstat (limited to 'test/timer-fail.cpp')
-rw-r--r--test/timer-fail.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/test/timer-fail.cpp b/test/timer-fail.cpp
index 2c622ca3..82854b89 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));
@@ -79,7 +81,7 @@ protected:
* to return 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;
@@ -90,13 +92,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_;
};