From 22231ec036268ca2adb1f0b0feed0a91ea68728f Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Sat, 14 Sep 2024 23:04:03 -0500 Subject: Start of virtual memory allocator; got an ICE, though! --- crates/utils/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'crates/utils') 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); + }}; +} -- cgit v1.2.3