Skip to content

Commit 12ee3b5

Browse files
Darksonnlelongg
authored andcommitted
Add TSAN support (tokio-rs#541)
1 parent 0186db6 commit 12ee3b5

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/bytes.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use alloc::{
1313
use crate::buf::IntoIter;
1414
#[allow(unused)]
1515
use crate::loom::sync::atomic::AtomicMut;
16-
use crate::loom::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering};
16+
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
1717
use crate::Buf;
1818

1919
/// A cheaply cloneable and sliceable chunk of contiguous memory.
@@ -1095,7 +1095,10 @@ unsafe fn release_shared(ptr: *mut Shared) {
10951095
// > "acquire" operation before deleting the object.
10961096
//
10971097
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
1098-
atomic::fence(Ordering::Acquire);
1098+
//
1099+
// Thread sanitizer does not support atomic fences. Use an atomic load
1100+
// instead.
1101+
(*ptr).ref_cnt.load(Ordering::Acquire);
10991102

11001103
// Drop the data
11011104
Box::from_raw(ptr);

src/bytes_mut.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::buf::{IntoIter, UninitSlice};
1616
use crate::bytes::Vtable;
1717
#[allow(unused)]
1818
use crate::loom::sync::atomic::AtomicMut;
19-
use crate::loom::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering};
19+
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
2020
use crate::{Buf, BufMut, Bytes};
2121

2222
/// A unique reference to a contiguous slice of memory.
@@ -1288,7 +1288,10 @@ unsafe fn release_shared(ptr: *mut Shared) {
12881288
// > "acquire" operation before deleting the object.
12891289
//
12901290
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
1291-
atomic::fence(Ordering::Acquire);
1291+
//
1292+
// Thread sanitizer does not support atomic fences. Use an atomic load
1293+
// instead.
1294+
(*ptr).ref_count.load(Ordering::Acquire);
12921295

12931296
// Drop the data
12941297
Box::from_raw(ptr);

src/loom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(not(all(test, loom)))]
22
pub(crate) mod sync {
33
pub(crate) mod atomic {
4-
pub(crate) use core::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};
4+
pub(crate) use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
55

66
pub(crate) trait AtomicMut<T> {
77
fn with_mut<F, R>(&mut self, f: F) -> R
@@ -23,7 +23,7 @@ pub(crate) mod sync {
2323
#[cfg(all(test, loom))]
2424
pub(crate) mod sync {
2525
pub(crate) mod atomic {
26-
pub(crate) use loom::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};
26+
pub(crate) use loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
2727

2828
pub(crate) trait AtomicMut<T> {}
2929
}

0 commit comments

Comments
 (0)