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_runningistrue, the owner callsupdate_timer_tickonce per second; - when
update_timer_tickreturnsfalsethe timer has stopped (the pool saw no activity for 21 ticks) and the owner stops calling it; - the timer starts again on the next
getorreturn_item. The optionalstart_timercallback given to the constructor is invoked each time that happens (and once from the constructor), so the owner does not have to polltimer_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>
impl<T, I: IBatchStreamPoolItems<T>> BatchStreamPoolBase<T, I>
pub fn new( items: I, reclaim_immediately: bool, start_timer: Option<BatchStreamPoolStartTimer>, ) -> Self
Sourcepub fn current_usage(&self) -> i32
pub fn current_usage(&self) -> i32
The number of items currently handed out.
Sourcepub fn current_pool(&self) -> i32
pub fn current_pool(&self) -> i32
The number of items currently kept in the pool.
Sourcepub fn timer_is_running(&self) -> bool
pub fn timer_is_running(&self) -> bool
Whether the owner is expected to call
update_timer_tick once per second.
Sourcepub fn update_timer_tick(&self) -> bool
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.
Sourcepub fn return_item(&self, item: T)
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.
Trait Implementations§
Source§impl<T, I: IBatchStreamPoolItems<T>> Drop for BatchStreamPoolBase<T, I>
impl<T, I: IBatchStreamPoolItems<T>> Drop for BatchStreamPoolBase<T, I>
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>
impl<T, I> Sync for BatchStreamPoolBase<T, I>
impl<T, I> Unpin for BatchStreamPoolBase<T, I>
impl<T, I> UnsafeUnpin for BatchStreamPoolBase<T, I>
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> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more