diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-01-25 12:53:32 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2024-04-26 18:19:39 +0200 |
commit | 7a374c38d288435b3c0a76b82a1c2ca53ea9c003 (patch) | |
tree | 77935a10880cbb4a8198a8a6700a4065369b3e66 /tests/auto | |
parent | 63f4708a9995af73a34986658fe4f0d2c1512588 (diff) |
QThread: Introduce isCurrentThread
This allows a more efficient way of checking whether a thread is the
currently executing one (without using private API).
Change-Id: I007edae6b258d7e42e901fa720d4f3cf9fe25a49
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/thread/qthread/tst_qthread.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index 9a53c5a48d..b163235d81 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -137,11 +137,13 @@ class Current_Thread : public QThread public: Qt::HANDLE id; QThread *thread; + bool runCalledInCurrentThread = false; void run() override { id = QThread::currentThreadId(); thread = QThread::currentThread(); + runCalledInCurrentThread = thread->isCurrentThread(); } }; @@ -276,6 +278,11 @@ void tst_QThread::currentThreadId() QVERIFY(thread.wait(five_minutes)); QVERIFY(thread.id != nullptr); QVERIFY(thread.id != QThread::currentThreadId()); + QVERIFY(!thread.isCurrentThread()); + QVERIFY(!thread.thread->isCurrentThread()); + QVERIFY(thread.QThread::thread()->isCurrentThread()); + QVERIFY(thread.runCalledInCurrentThread); + QVERIFY(qApp->thread()->isCurrentThread()); } void tst_QThread::currentThread() |