| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QAUDIO_RTSAN_SUPPORT_P_H |
| 5 | #define QAUDIO_RTSAN_SUPPORT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qtconfigmacros.h> |
| 19 | #include <QtCore/qtclasshelpermacros.h> |
| 20 | |
| 21 | #if defined(__has_feature) && __has_feature(realtime_sanitizer) |
| 22 | # include <sanitizer/rtsan_interface.h> |
| 23 | #endif |
| 24 | |
| 25 | // rtsan |
| 26 | #if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::nonblocking) |
| 27 | # define QT_MM_NONBLOCKING [[clang::nonblocking]] |
| 28 | #else |
| 29 | # define QT_MM_NONBLOCKING |
| 30 | #endif |
| 31 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | namespace QtPrivate { |
| 35 | |
| 36 | #if defined(__has_feature) && __has_feature(realtime_sanitizer) |
| 37 | using ScopedRTSanDisabler = __rtsan::ScopedDisabler; |
| 38 | #else |
| 39 | struct ScopedRTSanDisabler |
| 40 | { |
| 41 | ScopedRTSanDisabler() |
| 42 | { |
| 43 | // silence unused/unreferenced local variable warning |
| 44 | // NB: declaring the struct as [[maybe_unused]] does not work for cl.exe |
| 45 | (void)this; |
| 46 | } |
| 47 | ~ScopedRTSanDisabler() = default; |
| 48 | Q_DISABLE_COPY_MOVE(ScopedRTSanDisabler) |
| 49 | }; |
| 50 | #endif |
| 51 | |
| 52 | template <typename Functor> |
| 53 | auto withRTSanDisabled(const Functor &f) |
| 54 | { |
| 55 | #if defined(__has_feature) && __has_feature(realtime_sanitizer) |
| 56 | __rtsan::ScopedDisabler disabler; |
| 57 | #endif |
| 58 | return f(); |
| 59 | } |
| 60 | |
| 61 | } // namespace QtPrivate |
| 62 | |
| 63 | QT_END_NAMESPACE |
| 64 | |
| 65 | #endif // QAUDIO_RTSAN_SUPPORT_P_H |
| 66 | |