Skip to main content

BatchStreamPoolBase

Struct BatchStreamPoolBase 

Source
pub struct BatchStreamPoolBase<T, I: IBatchStreamPoolItems<T>> { /* private fields */ }
Expand description

A pool that keeps a number of elements that was used in the last 10 seconds

§Trimming

The C# class trims itself from a one second timer that it starts on the dispatcher of the thread it was created on (or through a startTimer delegate that receives the timer procedure). This port has no timer of its own; the owner drives it instead:

  • while timer_is_running is true, the owner calls update_timer_tick once per second;
  • when update_timer_tick returns false the timer has stopped (the pool saw no activity for 21 ticks) and the owner stops calling it;
  • the timer starts again on the next get or return_item. The optional start_timer callback given to the constructor is invoked each time that happens (and once from the constructor), so the owner does not have to poll timer_is_running. The callback is invoked on the thread that used the pool, outside of the pool lock.

A pool created with reclaim_immediately never keeps returned items and never asks for a timer.

Implementations§

Source§

impl<T, I: IBatchStreamPoolItems<T>> BatchStreamPoolBase<T, I>

Source

pub fn new( items: I, reclaim_immediately: bool, start_timer: Option<BatchStreamPoolStartTimer>, ) -> Self

Source

pub fn current_usage(&self) -> i32

The number of items currently handed out.

Source

pub fn current_pool(&self) -> i32

The number of items currently kept in the pool.

Source

pub fn timer_is_running(&self) -> bool

Whether the owner is expected to call update_timer_tick once per second.

Source

pub fn update_timer_tick(&self) -> bool

The timer procedure: trims the pool down to the number of items that were in use at the same time during the last 10 ticks (but keeps at least 10), and advances the usage statistics.

To be called by the owner once per second while the timer is running. Returns whether the timer keeps running.

Source

pub fn get(&self) -> T

Takes an item from the pool, creating one when the pool is empty.

Source

pub fn return_item(&self, item: T)

Gives an item back (C# Return). The item is cleared, and then kept for reuse unless the pool is disposed or reclaims immediately.

Source

pub fn dispose(&self)

Destroys the pooled items; items returned from now on are destroyed instead of being kept.

Trait Implementations§

Source§

impl<T, I: IBatchStreamPoolItems<T>> Drop for BatchStreamPoolBase<T, I>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T, I> !Freeze for BatchStreamPoolBase<T, I>

§

impl<T, I> !RefUnwindSafe for BatchStreamPoolBase<T, I>

§

impl<T, I> !UnwindSafe for BatchStreamPoolBase<T, I>

§

impl<T, I> Send for BatchStreamPoolBase<T, I>
where Mutex<PoolState<T>>: Send,

§

impl<T, I> Sync for BatchStreamPoolBase<T, I>
where Mutex<PoolState<T>>: Sync,

§

impl<T, I> Unpin for BatchStreamPoolBase<T, I>
where I: Unpin, Mutex<PoolState<T>>: Unpin,

§

impl<T, I> UnsafeUnpin for BatchStreamPoolBase<T, I>
where I: UnsafeUnpin, Mutex<PoolState<T>>: UnsafeUnpin,

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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, 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.