pub struct Pool<'p> { /* private fields */ }Expand description
The CPU resources one owner lends to every operation: a
threadteam::Pool (where tasks run) and an ArenaProvider (where
scratch lives).
The wrapper never starts threads itself; threadteam::PoolBuilder is
the only place a pool is made. Retain the wrapper across calls so its arena
is reused; Exec::new mints the per-call resource
bundle from it, and that constructor is the only place a thread budget is
clamped to the pool width.
§Examples
let sp = threadteam::Pool::builder().threads(3).build().unwrap();
let pool = tcontract_exec::Pool::borrow(&sp);
assert_eq!(pool.size(), sp.width().get());Implementations§
Source§impl<'p> Pool<'p>
impl<'p> Pool<'p>
Sourcepub fn borrow(pool: &'p Pool) -> Self
pub fn borrow(pool: &'p Pool) -> Self
Borrow a pool the host owns (an engine that keeps its own
threadteam::Pool).
Sourcepub fn workspace(&self) -> &ArenaProvider
pub fn workspace(&self) -> &ArenaProvider
The storage this pool lends to every operation that runs on it.
Borrowed, not copied: one pool is one owner, and a driver that is given this provider returns its team sets to it on drop.
Sourcepub fn trim_workspace(&self)
pub fn trim_workspace(&self)
Release the pool’s idle workspace storage. Live leases and borrowed worker buffers survive; a worker parked on this pool keeps its slot until it is idle again.
Source§impl Pool<'static>
impl Pool<'static>
Sourcepub fn owned(pool: Pool) -> Self
pub fn owned(pool: Pool) -> Self
Take ownership of a pool, for hosts without one of their own (the C ABI’s executors). Dropping the wrapper shuts the workers down.
§Examples
let sp = threadteam::Pool::builder().threads(2).build().unwrap();
let pool = tcontract_exec::Pool::owned(sp);
assert!(pool.size() >= 1);Share one threadteam::Pool between several wrappers, each with its
own workspace (the C ABI lends one pool handle to several executors). The
workers stop when the last wrapper is dropped.
§Examples
use std::sync::Arc;
let sp = Arc::new(threadteam::Pool::builder().threads(2).build().unwrap());
let a = tcontract_exec::Pool::shared(Arc::clone(&sp));
let b = tcontract_exec::Pool::shared(sp);
assert_eq!(a.size(), b.size());Trait Implementations§
Auto Trait Implementations§
impl<'p> !Freeze for Pool<'p>
impl<'p> !RefUnwindSafe for Pool<'p>
impl<'p> !UnwindSafe for Pool<'p>
impl<'p> Send for Pool<'p>
impl<'p> Sync for Pool<'p>
impl<'p> Unpin for Pool<'p>
impl<'p> UnsafeUnpin for Pool<'p>
Blanket Implementations§
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
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> ⓘ
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> ⓘ
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