Skip to content

Commit 425432b

Browse files
RalfJungcarllerche
authored andcommitted
use raw ptr for racy load and add comment (#289)
1 parent 4f5ed82 commit 425432b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/bytes.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,11 @@ impl Inner {
19401940

19411941
#[inline]
19421942
fn inline_len(&self) -> usize {
1943-
let p: &usize = unsafe { mem::transmute(&self.arc) };
1944-
(p & INLINE_LEN_MASK) >> INLINE_LEN_OFFSET
1943+
// This is undefind behavior due to a data race, but experimental
1944+
// evidence shows that it works in practice (discussion:
1945+
// https://internals.rust-lang.org/t/bit-wise-reasoning-for-atomic-accesses/8853).
1946+
let p: *const usize = unsafe { mem::transmute(&self.arc) };
1947+
(unsafe { *p } & INLINE_LEN_MASK) >> INLINE_LEN_OFFSET
19451948
}
19461949

19471950
/// Set the length of the inline buffer. This is done by writing to the

0 commit comments

Comments
 (0)