File indexing completed on 2026-09-17 09:25:17
0001
0002
0003
0004
0005
0006 #ifndef QTSAN_IMPL_H
0007 #define QTSAN_IMPL_H
0008
0009 #include <QtCore/qglobal.h>
0010
0011 #if (__has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)) && __has_include(<sanitizer/tsan_interface.h>)
0012 # define QT_BUILDING_UNDER_TSAN
0013 # include <sanitizer/tsan_interface.h>
0014 #endif
0015
0016 QT_BEGIN_NAMESPACE
0017
0018 namespace QtTsan {
0019 #ifdef QT_BUILDING_UNDER_TSAN
0020 inline void futexAcquire(void *addr, void *addr2 = nullptr)
0021 {
0022
0023
0024
0025 ::__tsan_acquire(addr);
0026 if (addr2)
0027 ::__tsan_acquire(addr2);
0028 }
0029
0030 inline void futexRelease(void *addr, void *addr2 = nullptr)
0031 {
0032 if (addr2)
0033 ::__tsan_release(addr2);
0034 ::__tsan_release(addr);
0035 }
0036
0037 inline void latchWait(const void *addr)
0038 {
0039 ::__tsan_acquire(const_cast<void *>(addr));
0040 }
0041
0042 inline void latchCountDown(void *addr)
0043 {
0044 ::__tsan_release(addr);
0045 }
0046
0047 inline void mutexPreLock(void *addr, unsigned flags)
0048 {
0049 ::__tsan_mutex_pre_lock(addr, flags);
0050 }
0051
0052 inline void mutexPostLock(void *addr, unsigned flags, int recursion)
0053 {
0054 ::__tsan_mutex_post_lock(addr, flags, recursion);
0055 }
0056
0057 inline void mutexPreUnlock(void *addr, unsigned flags)
0058 {
0059 ::__tsan_mutex_pre_unlock(addr, flags);
0060 }
0061
0062 inline void mutexPostUnlock(void *addr, unsigned flags)
0063 {
0064 ::__tsan_mutex_post_unlock(addr, flags);
0065 }
0066
0067 enum : unsigned {
0068 MutexWriteReentrant = ::__tsan_mutex_write_reentrant,
0069 TryLock = ::__tsan_mutex_try_lock,
0070 TryLockFailed = ::__tsan_mutex_try_lock_failed,
0071 ReadLock = ::__tsan_mutex_read_lock,
0072 };
0073 #else
0074 inline void futexAcquire(void *, void * = nullptr) {}
0075 inline void futexRelease(void *, void * = nullptr) {}
0076 inline void latchCountDown(void *) {}
0077 inline void latchWait(const void *) {}
0078
0079 enum : unsigned {
0080 MutexWriteReentrant,
0081 TryLock,
0082 TryLockFailed,
0083 ReadLock,
0084 };
0085 inline void mutexPreLock(void *, unsigned) {}
0086 inline void mutexPostLock(void *, unsigned, int) {}
0087 inline void mutexPreUnlock(void *, unsigned) {}
0088 inline void mutexPostUnlock(void *, unsigned) {}
0089 #endif
0090 }
0091
0092 QT_END_NAMESPACE
0093
0094 #endif