Skip to content

Commit af0b39e

Browse files
committed
1 parent 91b54d7 commit af0b39e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

hp-sharp/src/crcu/local.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,24 @@ impl Local {
103103
self.epoch.store(Epoch::starting(), Ordering::Release);
104104
}
105105

106+
/// `#[inline(never)]` is used to reduce the chances for misoptimizations.
107+
///
108+
/// In Rust, there is no concept of functions that return multiple times, like `setjmp`, so
109+
/// it's easy to imagine that Rust might generate incorrect code around such a function.
110+
///
111+
/// Rust uses LLVM during compilation, which needs to be made aware of functions that return
112+
/// multiple times by using the `returns_twice` attribute; but Rust has no way to propagate
113+
/// that attribute to LLVM.
114+
///
115+
/// Reference:
116+
/// * https://github.com/rust-lang/rfcs/issues/2625#issuecomment-460849462
117+
/// * https://github.com/jeff-davis/setjmp.rs#problems
106118
#[cfg(not(sanitize = "address"))]
107-
#[inline(always)]
119+
#[inline(never)]
108120
unsafe fn pin<F>(&mut self, mut body: F)
109121
where
110122
F: FnMut(&mut EpochGuard),
111123
{
112-
compiler_fence(Ordering::SeqCst);
113124
{
114125
// Makes a checkpoint and create a `RecoveryGuard`.
115126
let guard = recovery::guard!();
@@ -133,16 +144,14 @@ impl Local {
133144
// We are now out of the critical(crashable) section.
134145
// Unpin the local epoch to help reclaimers to freely collect bags.
135146
self.unpin_inner();
136-
compiler_fence(Ordering::SeqCst);
137147
}
138148

139149
#[cfg(sanitize = "address")]
140-
#[inline(always)]
150+
#[inline(never)]
141151
unsafe fn pin<F>(&mut self, mut body: F)
142152
where
143153
F: FnMut(&mut EpochGuard),
144154
{
145-
compiler_fence(Ordering::SeqCst);
146155
// A dummy loop to bypass a false stack overflow from AdressSanitizer.
147156
//
148157
// # HACK: A dummy loop and `blackbox`
@@ -187,7 +196,6 @@ impl Local {
187196
break;
188197
}
189198
}
190-
compiler_fence(Ordering::SeqCst);
191199
}
192200

193201
#[inline]

0 commit comments

Comments
 (0)