Skip to content

Commit

Permalink
use raw ptr for racy load and add comment (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung authored and carllerche committed Aug 28, 2019
1 parent 4f5ed82 commit 425432b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/bytes.rs
Expand Up @@ -1940,8 +1940,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
Expand Down

0 comments on commit 425432b

Please sign in to comment.