generated from al8n/template-rs
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove `SkipSet` - Add `insert`, `get_or_insert` and `get_or_insert_with` methods - Add `compare_remove` and `get_or_remove` methods - Add `Entry` and `VersionedEntry` - Add discard states tracker and `discarded` method to let users know how many bytes in ARENA are discarded. - Do not panic when users do not fully fill `VacantValue` - Add `tracing`
- Loading branch information
Showing
23 changed files
with
2,829 additions
and
4,817 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
msrv = "1.56.0" | ||
msrv = "1.75.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::sync::{AtomicU64, Ordering}; | ||
|
||
#[repr(C, align(8))] | ||
pub(crate) struct Pointer(AtomicU64); | ||
|
||
impl core::fmt::Debug for Pointer { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
let (offset, len) = decode_value(self.0.load(Ordering::Relaxed)); | ||
f.debug_struct("Pointer") | ||
.field("offset", &offset) | ||
.field("len", &len) | ||
.finish() | ||
} | ||
} | ||
|
||
impl Pointer { | ||
#[inline] | ||
pub(crate) fn new(offset: u32, len: u32) -> Self { | ||
Self(AtomicU64::new(encode_value(offset, len))) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn remove(offset: u32) -> Self { | ||
Self(AtomicU64::new(encode_value(offset, u32::MAX))) | ||
} | ||
|
||
#[cfg(not(feature = "unaligned"))] | ||
#[inline] | ||
pub(crate) fn load(&self, ordering: Ordering) -> (u32, u32) { | ||
decode_value(self.0.load(ordering)) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn swap(&self, offset: u32, len: u32) -> (u32, u32) { | ||
decode_value(self.0.swap(encode_value(offset, len), Ordering::AcqRel)) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn compare_remove( | ||
&self, | ||
success: Ordering, | ||
failure: Ordering, | ||
) -> Result<(u32, u32), (u32, u32)> { | ||
let old = self.0.load(Ordering::Acquire); | ||
let (offset, _) = decode_value(old); | ||
let new = encode_value(offset, u32::MAX); | ||
self | ||
.0 | ||
.compare_exchange(old, new, success, failure) | ||
.map(decode_value) | ||
.map_err(decode_value) | ||
} | ||
} | ||
|
||
#[inline] | ||
const fn encode_value(offset: u32, val_size: u32) -> u64 { | ||
(val_size as u64) << 32 | offset as u64 | ||
} | ||
|
||
#[inline] | ||
const fn decode_value(value: u64) -> (u32, u32) { | ||
let offset = value as u32; | ||
let val_size = (value >> 32) as u32; | ||
(offset, val_size) | ||
} |
Oops, something went wrong.