mod backoff;
mod cache_pad;
pub(crate) mod fmt;
mod maybe_uninit;
mod wake_batch;
pub use self::{backoff::Backoff, cache_pad::CachePadded};
pub(crate) use self::{maybe_uninit::CheckedMaybeUninit, wake_batch::WakeBatch};
#[cfg(any(test, feature = "tracing"))]
macro_rules! trace {
($($t:tt)*) => { tracing::trace!($($t)*) }
}
#[cfg(not(any(test, feature = "tracing")))]
macro_rules! trace {
($($t:tt)*) => {};
}
#[cfg(all(not(test), not(all(maitake_ultraverbose, feature = "tracing"))))]
macro_rules! test_dbg {
($e:expr) => {
$e
};
}
#[cfg(any(test, all(maitake_ultraverbose, feature = "tracing")))]
macro_rules! test_dbg {
($e:expr) => {
match $e {
e => {
tracing::debug!(
location = %core::panic::Location::caller(),
"{} = {:?}",
stringify!($e),
&e
);
e
}
}
};
}
#[cfg(all(not(test), not(all(maitake_ultraverbose, feature = "tracing"))))]
macro_rules! test_debug {
($($t:tt)*) => {};
}
#[cfg(any(test, all(maitake_ultraverbose, feature = "tracing")))]
macro_rules! test_debug {
($($t:tt)*) => { tracing::debug!($($t)*) }
}
#[cfg(all(not(test), not(all(maitake_ultraverbose, feature = "tracing"))))]
macro_rules! test_trace {
($($t:tt)*) => {};
}
#[cfg(any(test, all(maitake_ultraverbose, feature = "tracing")))]
macro_rules! test_trace {
($($t:tt)*) => { tracing::trace!($($t)*) }
}
#[cfg(all(not(test), not(all(maitake_ultraverbose, feature = "tracing"))))]
macro_rules! enter_test_debug_span {
($($args:tt)+) => {};
}
#[cfg(any(test, all(maitake_ultraverbose, feature = "tracing")))]
macro_rules! enter_test_debug_span {
($($args:tt)+) => {
let _span = tracing::debug_span!($($args)+).entered();
};
}
macro_rules! fmt_bits {
($self: expr, $f: expr, $has_states: ident, $($name: ident),+) => {
$(
if $self.contains(Self::$name) {
if $has_states {
$f.write_str(" | ")?;
}
$f.write_str(stringify!($name))?;
$has_states = true;
}
)+
};
}
macro_rules! feature {
(
#![$meta:meta]
$($item:item)*
) => {
$(
#[cfg($meta)]
#[cfg_attr(docsrs, doc(cfg($meta)))]
$item
)*
}
}
macro_rules! loom_const_fn {
(
$(#[$meta:meta])*
$vis:vis unsafe fn $name:ident($($arg:ident: $T:ty),*) -> $Ret:ty $body:block
) => {
$(#[$meta])*
#[cfg(not(loom))]
$vis const unsafe fn $name($($arg: $T),*) -> $Ret $body
$(#[$meta])*
#[cfg(loom)]
$vis unsafe fn $name($($arg: $T),*) -> $Ret $body
};
(
$(#[$meta:meta])*
$vis:vis fn $name:ident($($arg:ident: $T:ty),*) -> $Ret:ty $body:block
) => {
$(#[$meta])*
#[cfg(not(loom))]
$vis const fn $name($($arg: $T),*) -> $Ret $body
$(#[$meta])*
#[cfg(loom)]
$vis fn $name($($arg: $T),*) -> $Ret $body
}
}
macro_rules! unreachable_unchecked {
() => ({
#[cfg(any(test, debug_assertions))]
panic!(
concat!(
env!("CARGO_PKG_NAME"),
"internal error: entered unreachable code \n",
"/!\\ EXTREMELY SERIOUS WARNING: in release mode, this would have been\n",
" `unreachable_unchecked`! This could result in undefine behavior.\n",
" Please double- or triple-check any assumptions about code which\n,",
" could lead to this being triggered."
),
);
#[allow(unreachable_code)] {
core::hint::unreachable_unchecked();
}
});
($msg:expr) => ({
unreachable_unchecked!("{}", $msg)
});
($msg:expr,) => ({
unreachable_unchecked!($msg)
});
($fmt:expr, $($arg:tt)*) => ({
#[cfg(any(test, debug_assertions))]
panic!(
concat!(
env!("CARGO_PKG_NAME"),
"internal error: entered unreachable code: ",
$fmt,
"\n/!\\ EXTREMELY SERIOUS WARNING: in release mode, this would have been \n\
\x32 `unreachable_unchecked`! This could result in undefine behavior. \n\
\x32 Please double- or triple-check any assumptions about code which \n\
\x32 could lead to this being triggered."
),
$($arg)*
);
#[allow(unreachable_code)] {
core::hint::unreachable_unchecked();
}
});
}
#[cfg(all(test, not(loom)))]
pub(crate) use self::test::trace_init;
#[cfg(test)]
pub(crate) mod test {
#[must_use]
#[cfg(all(test, not(loom)))]
pub struct TestGuard {
_x1: tracing::subscriber::DefaultGuard,
}
#[cfg(all(test, not(loom)))]
pub(crate) fn trace_init() -> TestGuard {
trace_init_with_default("maitake=debug,cordyceps=debug")
}
#[cfg(all(test, not(loom)))]
pub(crate) fn trace_init_with_default(default: &str) -> TestGuard {
use tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
util::SubscriberInitExt,
};
const ENV: &str = if cfg!(loom) { "LOOM_LOG" } else { "RUST_LOG" };
let env = std::env::var(ENV).unwrap_or_default();
let builder = EnvFilter::builder().with_default_directive(LevelFilter::INFO.into());
let filter = if env.is_empty() {
builder
.parse(default)
.unwrap()
.add_directive("loom=info".parse().unwrap())
} else {
builder.parse_lossy(env)
};
let collector = tracing_subscriber::fmt()
.with_env_filter(filter)
.with_test_writer()
.without_time()
.finish();
TestGuard {
_x1: collector.set_default(),
}
}
#[allow(dead_code)]
pub(crate) fn assert_send<T: Send>() {}
#[allow(dead_code)]
pub(crate) fn assert_sync<T: Sync>() {}
pub(crate) fn assert_send_sync<T: Send + Sync>() {}
}