diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-06-11 14:20:48 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2024-06-12 07:23:36 +0200 |
| commit | d73a2bf0fb3e0a00691c858645a5a5bb2b55b40a (patch) | |
| tree | 3c84a37f617acfef9961efbe1b874daac89648bc /src/corelib/thread/qthread.cpp | |
| parent | b58d926090620079f602f4f2ce9f17fe7025c962 (diff) | |
QThread: mark is(Main|Current)Thread() noexcept
The rationale given for the addition of these functions was that they
are a more efficient way to check these things in public API.
If so, they shouldn't cause compilers to insert exception handling
around their calls, so mark them noexcept.
This is safe, as both conceptually and practically, these functions
should not and cannot fail, so we'll never need to remove noexcept
again.
Found in API-Review.
Amends 7a374c38d288435b3c0a76b82a1c2ca53ea9c003 and
a3d50112e44bc42b310d9d3a8e6c7805ef31ef53.
These two commits also lacked each the changelog entry, so adding them
here:
[ChangeLog][QtCore][QThread] Added isMainThread() static member
function.
[ChangeLog][QtCore][QThread] Added isCurrentThread() member function.
Pick-to: 6.8
Change-Id: Iaf39ce2cc0abd45049bff60b24693e84bf76d9e0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qthread.cpp')
| -rw-r--r-- | src/corelib/thread/qthread.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index ea76a2ccada..738c3846c53 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -438,7 +438,7 @@ QThread *QThread::currentThread() \sa currentThread(), QCoreApplication::instance() */ -bool QThread::isMainThread() +bool QThread::isMainThread() noexcept { return currentThreadId() == QCoreApplicationPrivate::theMainThreadId.loadRelaxed(); } @@ -952,7 +952,7 @@ int QThread::loopLevel() const therefore give surprising results if it outlives the QThread object (threads claimed to be the same even if they aren't). */ -Qt::HANDLE QThreadPrivate::threadId() const +Qt::HANDLE QThreadPrivate::threadId() const noexcept { return data->threadId.loadRelaxed(); } @@ -963,7 +963,7 @@ Qt::HANDLE QThreadPrivate::threadId() const \sa currentThreadId() */ -bool QThread::isCurrentThread() const +bool QThread::isCurrentThread() const noexcept { Q_D(const QThread); return QThread::currentThreadId() == d->threadId(); @@ -1041,7 +1041,7 @@ QThread *QThread::currentThread() return QThreadData::current()->thread.loadAcquire(); } -bool QThread::isCurrentThread() const +bool QThread::isCurrentThread() const noexcept { return true; } |
