Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions include/asio/detail/std_fenced_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@

#include "asio/detail/push_options.hpp"

#if defined(__has_feature)
# if __has_feature(thread_sanitizer)
# include "sanitizer/tsan_interface.h"
# define USE_TSAN_SEMANTICS 1
# else
# define USE_TSAN_SEMANTICS 0
# endif
#else
# define USE_TSAN_SEMANTICS 0
#endif

namespace asio {
ASIO_INLINE_NAMESPACE_BEGIN
namespace detail {
Expand All @@ -40,14 +51,27 @@ class std_fenced_block
// Constructor for a full fenced block.
explicit std_fenced_block(full_t)
{
#if USE_TSAN_SEMANTICS
__tsan_acquire(&tsan);
#else
std::atomic_thread_fence(std::memory_order_acquire);
#endif
}

// Destructor.
~std_fenced_block()
{
#if USE_TSAN_SEMANTICS
__tsan_release(&tsan);
#else
std::atomic_thread_fence(std::memory_order_release);
#endif
}

#if USE_TSAN_SEMANTICS
private:
int tsan;
#endif
};

} // namespace detail
Expand Down