// Copyright 2025 Jonas Kruckenberg // // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. use cfg_if::cfg_if; cfg_if! { if #[cfg(loom)] { pub(crate) use loom::sync; pub(crate) use loom::cell; pub(crate) use loom::model; #[cfg(test)] pub(crate) use loom::thread; pub(crate) use loom::lazy_static; pub(crate) use loom::thread_local; } else { #[cfg(any(test, feature = "__bench"))] pub(crate) use std::thread; #[cfg(any(test, feature = "__bench"))] pub(crate) use std::thread_local; #[cfg(test)] pub(crate) use lazy_static::lazy_static; #[cfg(test)] #[inline(always)] pub(crate) fn model(f: impl FnOnce() -> R) -> R { f() } pub(crate) mod sync { pub use core::sync::*; #[cfg(any(test, feature = "__bench"))] pub(crate) use std::sync::*; } pub(crate) mod cell { #[derive(Debug)] pub(crate) struct UnsafeCell(core::cell::UnsafeCell); impl UnsafeCell { pub(crate) const fn new(data: T) -> UnsafeCell { UnsafeCell(core::cell::UnsafeCell::new(data)) } #[inline(always)] pub(crate) fn with(&self, f: impl FnOnce(*const T) -> R) -> R { f(self.0.get()) } #[inline(always)] pub(crate) fn with_mut(&self, f: impl FnOnce(*mut T) -> R) -> R { f(self.0.get()) } } } } } // #[derive(Debug)] // #[pin_project::pin_project] // pub(crate) struct TrackFuture { // #[pin] // inner: F, // track: Arc<()>, // } // // impl Future for TrackFuture { // type Output = TrackFuture; // fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { // let this = self.project(); // this.inner.poll(cx).map(|inner| TrackFuture { // inner, // track: this.track.clone(), // }) // } // } // // impl TrackFuture { // /// Wrap a `Future` in a `TrackFuture` that participates in Loom's // /// leak checking. // #[track_caller] // pub(crate) fn new(inner: F) -> Self { // Self { // inner, // track: Arc::new(()), // } // } // // /// Stop tracking this future, and return the inner value. // pub(crate) fn into_inner(self) -> F { // self.inner // } // } // // #[track_caller] // pub(crate) fn track_future(inner: F) -> TrackFuture { // TrackFuture::new(inner) // } // // // PartialEq impl so that `assert_eq!(..., Ok(...))` works // impl PartialEq for TrackFuture { // fn eq(&self, other: &Self) -> bool { // self.inner == other.inner // } // } // } // } else { // // // } // }