diff --git a/test/atomicity.cpp b/test/atomicity.cpp index 3688ab4..3719d17 100644 --- a/test/atomicity.cpp +++ b/test/atomicity.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "test_config.hpp" #include "test_clock.hpp" /* helper class to let two instances of a function race against each @@ -120,6 +121,7 @@ private: std::thread second_thread_; }; +BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD bool racy_add(unsigned int volatile& value, std::size_t instance) { std::size_t shift = instance * 8; @@ -142,6 +144,7 @@ bool racy_add(unsigned int volatile& value, std::size_t instance) } /* compute estimate for average time between races being observable, in usecs */ +BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD double estimate_avg_race_time(void) { double sum = 0.0; diff --git a/test/atomicity_ref.cpp b/test/atomicity_ref.cpp index b2b83cd..c5bdcbe 100644 --- a/test/atomicity_ref.cpp +++ b/test/atomicity_ref.cpp @@ -39,6 +39,7 @@ #include #include #include +#include "test_config.hpp" #include "test_clock.hpp" /* helper class to let two instances of a function race against each @@ -124,6 +125,7 @@ private: std::thread second_thread_; }; +BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD bool racy_add(unsigned int volatile& value, std::size_t instance) { std::size_t shift = instance * 8; @@ -146,6 +148,7 @@ bool racy_add(unsigned int volatile& value, std::size_t instance) } /* compute estimate for average time between races being observable, in usecs */ +BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD double estimate_avg_race_time(void) { double sum = 0.0; diff --git a/test/test_config.hpp b/test/test_config.hpp new file mode 100644 index 0000000..8caa7d3 --- /dev/null +++ b/test/test_config.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2025 Andrey Semashev +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_ATOMIC_TEST_TEST_CONFIG_HPP_INCLUDED_ +#define BOOST_ATOMIC_TEST_TEST_CONFIG_HPP_INCLUDED_ + +#include + +#if defined(TSAN) && defined(__GNUC__) + +// Suppresses TSAN for a marked function +#define BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD __attribute__((no_sanitize("thread"))) + +#else // defined(TSAN) && defined(__GNUC__) + +#define BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD + +#endif // defined(TSAN) && defined(__GNUC__) + +#endif // BOOST_ATOMIC_TEST_TEST_CONFIG_HPP_INCLUDED_