Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use atomic_thread_fence under TSAN #544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions include/EASTL/internal/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1836,4 +1836,18 @@ typedef EASTL_SSIZE_T eastl_ssize_t; // Signed version of eastl_size_t. Concept
EA_RESTORE_VC_WARNING(); \
EA_RESTORE_GCC_WARNING();

#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
#define EASTL_TSAN_ENABLED 1
#else
#define EASTL_TSAN_ENABLED 0
#endif
#else
#if defined(__SANITIZE_THREAD__)
#define EASTL_TSAN_ENABLED 1
#else
#define EASTL_TSAN_ENABLED 0
#endif
#endif

#endif // Header include guard
36 changes: 25 additions & 11 deletions include/EASTL/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,19 @@ namespace eastl
inline void ref_count_sp::release()
{
EASTL_ASSERT((mRefCount.load(memory_order_relaxed) > 0));
if(mRefCount.fetch_sub(1, memory_order_release) == 1)
{
atomic_thread_fence(memory_order_acquire);
free_value();
}

#if !EASTL_TSAN_ENABLED
if(mRefCount.fetch_sub(1, memory_order_release) == 1)
{
atomic_thread_fence(memory_order_acquire);
free_value();
}
#else
// NOTE: TSAN does not support atomic_thread_fences
if(mRefCount.fetch_sub(1, memory_order_acq_rel) == 1)
{
free_value();
}
#endif
weak_release();
}

Expand All @@ -179,11 +186,18 @@ namespace eastl
inline void ref_count_sp::weak_release()
{
EASTL_ASSERT(mWeakRefCount.load(memory_order_relaxed) > 0);
if(mWeakRefCount.fetch_sub(1, memory_order_release) == 1)
{
atomic_thread_fence(memory_order_acquire);
free_ref_count_sp();
}
#if !EASTL_TSAN_ENABLED
if(mWeakRefCount.fetch_sub(1, memory_order_release) == 1)
{
atomic_thread_fence(memory_order_acquire);
free_ref_count_sp();
}
#else
if(mWeakRefCount.fetch_sub(1, memory_order_acq_rel) == 1)
{
free_ref_count_sp();
}
#endif
}

inline ref_count_sp* ref_count_sp::lock() EA_NOEXCEPT
Expand Down