mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-23 00:00:13 +02:00
use raw ptr for racy load and add comment (#289)
This commit is contained in:
+5
-2
@@ -1940,8 +1940,11 @@ impl Inner {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inline_len(&self) -> usize {
|
fn inline_len(&self) -> usize {
|
||||||
let p: &usize = unsafe { mem::transmute(&self.arc) };
|
// This is undefind behavior due to a data race, but experimental
|
||||||
(p & INLINE_LEN_MASK) >> INLINE_LEN_OFFSET
|
// 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
|
/// Set the length of the inline buffer. This is done by writing to the
|
||||||
|
|||||||
Reference in New Issue
Block a user