userver: userver/compiler/impl/tsan.hpp Source File
Loading...
Searching...
No Matches
tsan.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/compiler/impl/tsan.hpp
4/// @brief Defines USERVER_IMPL_HAS_TSAN to 1 and includes
5/// <sanitizer/tsan_interface.h> if Thread Sanitizer is enabled; otherwise
6/// defines USERVER_IMPL_HAS_TSAN to 0.
7
8#if defined(__has_feature)
9
10#if __has_feature(thread_sanitizer)
11// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
12#define USERVER_IMPL_HAS_TSAN 1
13#else
14// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
15#define USERVER_IMPL_HAS_TSAN 0
16#endif
17
18#else
19// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
20#define USERVER_IMPL_HAS_TSAN 0
21#endif
22
24#include <sanitizer/tsan_interface.h>
25#endif
26
27#if USERVER_IMPL_HAS_TSAN && !defined(BOOST_USE_TSAN)
28#error Broken CMake: thread sanitizer is used however Boost is unaware of it
29#endif
30
31#if !USERVER_IMPL_HAS_TSAN && defined(BOOST_USE_TSAN)
32#error Broken CMake: thread sanitizer is not used however Boost thinks it is
33#endif
34
35#ifdef __clang__
36// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
37#define USERVER_IMPL_DISABLE_TSAN __attribute__((no_sanitize_thread))
38#else
39// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
40#define USERVER_IMPL_DISABLE_TSAN
41#endif