diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-09-14 23:04:03 -0500 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-09-14 23:04:03 -0500 |
commit | 22231ec036268ca2adb1f0b0feed0a91ea68728f (patch) | |
tree | 79dc49db7bd7758a7eb40a64828628461930b228 /crates/utils/src/lib.rs | |
parent | 0392b41e7081c11caa9d04aa738bdac97062e9dd (diff) |
Start of virtual memory allocator; got an ICE, though!
Diffstat (limited to 'crates/utils/src/lib.rs')
-rw-r--r-- | crates/utils/src/lib.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 6e26317..c6681d9 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -23,7 +23,7 @@ pub fn debug(f: impl Fn(&mut fmt::Formatter) -> fmt::Result) -> impl fmt::Debug /// A hint that this branch is unlikely to be called. #[cold] #[inline(always)] -fn cold() {} +pub fn cold() {} /// A hint that `b` is likely to be true. See `core::intrinsics::likely`. #[inline(always)] @@ -130,3 +130,15 @@ macro_rules! impl_FromEndianBytes { } impl_FromEndianBytes!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize); + +/// Runs the body block the first time it is encountered. +#[macro_export] +macro_rules! first_time { + ($($stmt:stmt);*) => {{ + use core::cell::LazyCell; + static LAZY_CELL = LazyCell::new(|| { + $($stmt);* + }); + let _: &() = core::cell::LazyCell::force(&LAZY_CELL); + }}; +} |