Skip to main content

Pool

Struct Pool 

Source
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>

Source

pub fn borrow(pool: &'p Pool) -> Self

Borrow a pool the host owns (an engine that keeps its own threadteam::Pool).

Source

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.

Source

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

pub fn size(&self) -> usize

Number of workers, the largest budget Exec::new grants.

Source§

impl Pool<'static>

Source

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);
Source

pub fn shared(pool: Arc<Pool>) -> Self

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§

Source§

impl Debug for Pool<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.