diff options
| author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-04-10 12:29:47 +0200 |
|---|---|---|
| committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-04-11 23:26:01 +0200 |
| commit | b2233f19c9be9b87f4a49a4169aab6f5e7617563 (patch) | |
| tree | 134f283d5efd27d02e461a9405ff6ea26ab0c347 /src/corelib/thread/qmutex.cpp | |
| parent | e9962537743333059b4857ce63e9888cb9591774 (diff) | |
Annotate QMutex with TSAN annotations
The Q(Basic)Mutex fast paths are entirely inline in the caller, which
means we need to annotate its operations directly or TSAN doesn't know
what's going on. Also annotate QRecursiveMutex.
The tryLock code could be in principle simplified via a QScopeGuard
but I didn't want to make a central class like QMutex depend on it.
[ChangeLog][QtCore][QMutex] QMutex now has annotations for
ThreadSanitizer.
Change-Id: Ibb130404e63a5ec9bcef9675f9addd16a2c38b7f
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qmutex.cpp')
| -rw-r--r-- | src/corelib/thread/qmutex.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 1e3ba796247..d88658ab499 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -334,10 +334,14 @@ QRecursiveMutex::~QRecursiveMutex() */ bool QRecursiveMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT { + unsigned tsanFlags = QtTsan::MutexWriteReentrant | QtTsan::TryLock; + QtTsan::mutexPreLock(this, tsanFlags); + Qt::HANDLE self = QThread::currentThreadId(); if (owner.loadRelaxed() == self) { ++count; Q_ASSERT_X(count != 0, "QMutex::lock", "Overflow in recursion counter"); + QtTsan::mutexPostLock(this, tsanFlags, 0); return true; } bool success = true; @@ -349,6 +353,11 @@ bool QRecursiveMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT if (success) owner.storeRelaxed(self); + else + tsanFlags |= QtTsan::TryLockFailed; + + QtTsan::mutexPostLock(this, tsanFlags, 0); + return success; } @@ -412,6 +421,7 @@ bool QRecursiveMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT void QRecursiveMutex::unlock() noexcept { Q_ASSERT(owner.loadRelaxed() == QThread::currentThreadId()); + QtTsan::mutexPreUnlock(this, 0u); if (count > 0) { count--; @@ -419,6 +429,8 @@ void QRecursiveMutex::unlock() noexcept owner.storeRelaxed(nullptr); mutex.unlock(); } + + QtTsan::mutexPostUnlock(this, 0u); } |
