pub struct RayonLanes<'d> { /* private fields */ }Expand description
The Lanes implementation over a domain’s Rayon pool.
Creating one admits the domain, so the executor holds the domain’s one coarse
operation slot for its whole lifetime. Each lane is one Rayon worker; the
lane resource is () because the callback already runs on that worker.
Entry from a Rayon worker that does not belong to the domain pool is rejected, and so is entry while another operation owns the domain.
§Example
use hataori::{Domain, Lanes, RayonLanes};
use std::sync::Arc;
let pool = Arc::new(rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap());
let domain = Domain::external(Arc::clone(&pool), vec![0, 1], 2).unwrap();
let mut lanes = RayonLanes::new(&domain).unwrap();
assert_eq!(lanes.lane_count(), 2);
let visited = std::sync::atomic::AtomicUsize::new(0);
lanes
.run(|_index, (), _control| {
visited.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
Ok::<_, std::convert::Infallible>(())
})
.unwrap();
assert_eq!(visited.into_inner(), 2);Implementations§
Source§impl<'d> RayonLanes<'d>
impl<'d> RayonLanes<'d>
Sourcepub fn new(domain: &'d Domain) -> Result<Self, RayonLanesError>
pub fn new(domain: &'d Domain) -> Result<Self, RayonLanesError>
Admits domain and builds a lane executor over its pool.
§Errors
Returns RayonLanesError::MissingPool for a domain without a pool,
RayonLanesError::ForeignPool when called from a different Rayon pool,
and RayonLanesError::DomainBusy when the domain is already admitted.
Trait Implementations§
Source§impl Lanes for RayonLanes<'_>
impl Lanes for RayonLanes<'_>
Source§type Error = Infallible
type Error = Infallible
A lane entry, join, or cleanup failure.
Source§fn lane_count(&self) -> usize
fn lane_count(&self) -> usize
Returns the number of lanes the executor runs.
Source§fn run<E: Send>(
&mut self,
lane: impl Fn(usize, &mut (), &LaneControl<'_>) -> Result<(), E> + Sync,
) -> Result<(), LanesError<E, Self::Error>>
fn run<E: Send>( &mut self, lane: impl Fn(usize, &mut (), &LaneControl<'_>) -> Result<(), E> + Sync, ) -> Result<(), LanesError<E, Self::Error>>
Runs
lane on every lane, joins all of them, then resumes a lane panic. Read moreSource§fn run_with_coordinator<C, E: Send>(
&mut self,
coordinator: impl FnOnce(&LaneControl<'_>) -> Result<C, E>,
lane: impl Fn(usize, &mut (), &LaneControl<'_>) -> Result<(), E> + Sync,
) -> Result<C, LanesError<E, Self::Error>>
fn run_with_coordinator<C, E: Send>( &mut self, coordinator: impl FnOnce(&LaneControl<'_>) -> Result<C, E>, lane: impl Fn(usize, &mut (), &LaneControl<'_>) -> Result<(), E> + Sync, ) -> Result<C, LanesError<E, Self::Error>>
Runs
coordinator on the calling thread concurrently with every lane. Read moreAuto Trait Implementations§
impl<'d> !RefUnwindSafe for RayonLanes<'d>
impl<'d> !UnwindSafe for RayonLanes<'d>
impl<'d> Freeze for RayonLanes<'d>
impl<'d> Send for RayonLanes<'d>
impl<'d> Sync for RayonLanes<'d>
impl<'d> Unpin for RayonLanes<'d>
impl<'d> UnsafeUnpin for RayonLanes<'d>
Blanket Implementations§
§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Approximate the subject to a given type with the default scheme.
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Approximate the subject to a given type with a specific scheme.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<Src> TryFrom<Src> for Src
impl<Src> TryFrom<Src> for Src
§impl<Src, Dst> TryInto<Dst> for Srcwhere
Dst: TryFrom<Src>,
impl<Src, Dst> TryInto<Dst> for Srcwhere
Dst: TryFrom<Src>,
§impl<Src> ValueFrom<Src> for Src
impl<Src> ValueFrom<Src> for Src
§fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
Convert the given value into an exactly equivalent representation.