Skip to content

Add TSAN support #541

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

Merged
merged 4 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ unsafe fn shallow_clone_vec(

unsafe fn release_shared(ptr: *mut Shared) {
// `Shared` storage... follow the drop steps from Arc.
if (*ptr).ref_cnt.fetch_sub(1, Ordering::Release) != 1 {
if (*ptr).ref_cnt.fetch_sub(1, Ordering::AcqRel) != 1 {
return;
}

Expand All @@ -1082,7 +1082,13 @@ unsafe fn release_shared(ptr: *mut Shared) {
// > "acquire" operation before deleting the object.
//
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
atomic::fence(Ordering::Acquire);
//#[cfg(not(thread = "sanitize"))]
//atomic::fence(Ordering::Acquire);

// Thread sanitizer does not support atomic fences. Use an atomic load
// instead.
//#[cfg(thread = "sanitize")]
//(*ptr).ref_count.load(Ordering::Acquire);

// Drop the data
Box::from_raw(ptr);
Expand Down
10 changes: 8 additions & 2 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ unsafe fn increment_shared(ptr: *mut Shared) {

unsafe fn release_shared(ptr: *mut Shared) {
// `Shared` storage... follow the drop steps from Arc.
if (*ptr).ref_count.fetch_sub(1, Ordering::Release) != 1 {
if (*ptr).ref_count.fetch_sub(1, Ordering::AcqRel) != 1 {
return;
}

Expand All @@ -1287,7 +1287,13 @@ unsafe fn release_shared(ptr: *mut Shared) {
// > "acquire" operation before deleting the object.
//
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
atomic::fence(Ordering::Acquire);
//#[cfg(not(thread = "sanitize"))]
//atomic::fence(Ordering::Acquire);

// Thread sanitizer does not support atomic fences. Use an atomic load
// instead.
//#[cfg(thread = "sanitize")]
//(*ptr).ref_count.load(Ordering::Acquire);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like everything is commented out.


// Drop the data
Box::from_raw(ptr);
Expand Down
2 changes: 2 additions & 0 deletions src/loom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(not(all(test, loom)))]
pub(crate) mod sync {
pub(crate) mod atomic {
#[allow(unused_imports)]
pub(crate) use core::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};

pub(crate) trait AtomicMut<T> {
Expand All @@ -23,6 +24,7 @@ pub(crate) mod sync {
#[cfg(all(test, loom))]
pub(crate) mod sync {
pub(crate) mod atomic {
#[allow(unused_imports)]
pub(crate) use loom::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};

pub(crate) trait AtomicMut<T> {}
Expand Down