Skip to content

Commit b9eb476

Browse files
committed
Make crossbeam-epoch compatible with ThreadSanitizer
1 parent a57e655 commit b9eb476

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

ci/tsan

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# TSAN suppressions file for crossbeam
22

3-
# The epoch-based GC uses fences.
4-
race:crossbeam_epoch
5-
63
# Push and steal operations in crossbeam-deque may cause data races, but such
74
# data races are safe. If a data race happens, the value read by `steal` is
85
# forgotten and the steal operation is then retried.

crossbeam-epoch/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// The rustc-cfg emitted by the build script are *not* public API.
2+
3+
use std::env;
4+
5+
fn main() {
6+
println!("cargo:rerun-if-changed=no_atomic.rs");
7+
8+
// `cfg(sanitize = "..")` is not stabilized.
9+
let sanitize = env::var("CARGO_CFG_SANITIZE").unwrap_or_default();
10+
if sanitize.contains("thread") {
11+
println!("cargo:rustc-cfg=crossbeam_sanitize_thread");
12+
}
13+
}

crossbeam-epoch/src/internal.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,16 @@ impl Global {
249249
if local_epoch.is_pinned() && local_epoch.unpinned() != global_epoch {
250250
return global_epoch;
251251
}
252+
253+
if cfg!(crossbeam_sanitize_thread) {
254+
local.epoch.load(Ordering::Acquire);
255+
}
252256
}
253257
}
254258
}
255-
atomic::fence(Ordering::Acquire);
259+
if !cfg!(crossbeam_sanitize_thread) {
260+
atomic::fence(Ordering::Acquire);
261+
}
256262

257263
// All pinned participants were pinned in the current global epoch.
258264
// Now let's advance the global epoch...

0 commit comments

Comments
 (0)