pub(crate) use std::io::Result;
pub(crate) use variant::*;
#[cfg(all(feature = "io-driver", not(loom)))]
mod variant {
use crate::io::driver;
use crate::park::{Either, ParkThread};
use std::io;
pub(crate) type Driver = Either<driver::Driver, ParkThread>;
pub(crate) type Handle = Option<driver::Handle>;
pub(crate) fn create_driver(enable: bool) -> io::Result<(Driver, Handle)> {
if enable {
let driver = driver::Driver::new()?;
let handle = driver.handle();
Ok((Either::A(driver), Some(handle)))
} else {
let driver = ParkThread::new();
Ok((Either::B(driver), None))
}
}
pub(crate) fn set_default(handle: &Handle) -> Option<driver::DefaultGuard<'_>> {
handle.as_ref().map(|handle| driver::set_default(handle))
}
}
#[cfg(any(not(feature = "io-driver"), loom))]
mod variant {
use crate::park::ParkThread;
use std::io;
pub(crate) type Driver = ParkThread;
pub(crate) type Handle = ();
pub(crate) fn create_driver(_enable: bool) -> io::Result<(Driver, Handle)> {
let driver = ParkThread::new();
Ok((driver, ()))
}
pub(crate) fn set_default(_handle: &Handle) {}
}