[][src]Struct lockfree_object_pool::SpinLockObjectPool

pub struct SpinLockObjectPool<T> { /* fields omitted */ }

ObjectPool use a spin lock over vector to secure multithread access to pull.

The spin lock works like std::sync::Mutex but

cf wikipedia for more information.

Example

 use lockfree_object_pool::SpinLockObjectPool;

 let pool = SpinLockObjectPool::<u32>::new(
   ||  Default::default(),
   |v| {
     *v = 0;
   }
 );
 let mut item = pool.pull();

 *item = 5;
 let work = *item * 5;

Implementations

impl<T> SpinLockObjectPool<T>[src]

pub fn new<R, I>(init: I, reset: R) -> Self where
    R: Fn(&mut T) + Send + Sync + 'static,
    I: Fn() -> T + Send + Sync + 'static, 
[src]

Create an new SpinLockObjectPool

Arguments

  • init closure to create new item
  • reset closure to reset item before reusage

Example

 use lockfree_object_pool::SpinLockObjectPool;

 let pool = SpinLockObjectPool::<u32>::new(
   ||  Default::default(),
   |v| {
     *v = 0;
   }
 );

pub fn pull(&self) -> SpinLockReusable<'_, T>[src]

Create a new element. When the element is dropped, it returns in the pull.

Example

 use lockfree_object_pool::SpinLockObjectPool;

 let pool = SpinLockObjectPool::<u32>::new(
   ||  Default::default(),
   |v| {
     *v = 0;
   }
 );
 let mut item = pool.pull();

Auto Trait Implementations

impl<T> !RefUnwindSafe for SpinLockObjectPool<T>[src]

impl<T> Send for SpinLockObjectPool<T> where
    T: Send
[src]

impl<T> Sync for SpinLockObjectPool<T> where
    T: Send
[src]

impl<T> Unpin for SpinLockObjectPool<T> where
    T: Unpin
[src]

impl<T> !UnwindSafe for SpinLockObjectPool<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.