From fc68afbb17574e4d29fa896d6768928273fbb65b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 27 Aug 2019 09:45:04 +0200 Subject: [PATCH] use raw ptr for racy load and add comment --- src/bytes.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bytes.rs b/src/bytes.rs index 3f8b23a6f..1a902d48a 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -1943,8 +1943,11 @@ impl Inner { #[inline] fn inline_len(&self) -> usize { - let p: &usize = unsafe { mem::transmute(&self.arc) }; - (p & INLINE_LEN_MASK) >> INLINE_LEN_OFFSET + // This is undefind behavior due to a data race, but experimental + // evidence shows that it works in practice (discussion: + // https://internals.rust-lang.org/t/bit-wise-reasoning-for-atomic-accesses/8853). + let p: *const usize = unsafe { mem::transmute(&self.arc) }; + (unsafe { *p } & INLINE_LEN_MASK) >> INLINE_LEN_OFFSET } /// Set the length of the inline buffer. This is done by writing to the