Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::concurrent::ObjectPool< T > Class Template Reference

Concurrent object pool. More...

#include <ObjectPool.h>

Inheritance diagram for sese::concurrent::ObjectPool< T >:
sese::Noncopyable

Public Types

using Ptr = std::shared_ptr<ObjectPool<T>>
 
using ObjectPtr = std::shared_ptr<T>
 

Public Member Functions

 ~ObjectPool () override
 
ObjectPtr borrow ()
 
- Public Member Functions inherited from sese::Noncopyable
 Noncopyable ()=default
 
virtual ~Noncopyable ()=default
 
 Noncopyable (const Noncopyable &)=delete
 
Noncopyableoperator= (const Noncopyable &)=delete
 

Static Public Member Functions

static Ptr create ()
 

Private Member Functions

 ObjectPool ()=default
 

Static Private Member Functions

static void recycleCallback (const std::weak_ptr< ObjectPool< T > > &wk_pool, T *t)
 

Private Attributes

LinkedQueue< T * > queue
 

Detailed Description

template<typename T>
class sese::concurrent::ObjectPool< T >

Concurrent object pool.

Template Parameters
TThe type of objects in the pool

Member Typedef Documentation

◆ ObjectPtr

template<typename T >
using sese::concurrent::ObjectPool< T >::ObjectPtr = std::shared_ptr<T>

◆ Ptr

template<typename T >
using sese::concurrent::ObjectPool< T >::Ptr = std::shared_ptr<ObjectPool<T>>

Constructor & Destructor Documentation

◆ ~ObjectPool()

◆ ObjectPool()

template<typename T >
sese::concurrent::ObjectPool< T >::ObjectPool ( )
privatedefault

Member Function Documentation

◆ borrow()

template<typename T >
ObjectPtr sese::concurrent::ObjectPool< T >::borrow ( )
inline

Retrieves a reusable object from the object pool

Returns
The object

References sese::concurrent::LinkedQueue< T >::pop(), sese::concurrent::ObjectPool< T >::queue, and sese::concurrent::ObjectPool< T >::recycleCallback().

◆ create()

template<typename T >
static Ptr sese::concurrent::ObjectPool< T >::create ( )
inlinestatic

The object pool can only be created on the heap

Returns
A smart pointer to the object pool

◆ recycleCallback()

template<typename T >
static void sese::concurrent::ObjectPool< T >::recycleCallback ( const std::weak_ptr< ObjectPool< T > > & wk_pool,
T * t )
inlinestaticprivate

Destructor for the borrowed object

Parameters
wk_poolA weak pointer to the object pool that the object belongs to, used for triggering the recycling logic
tThe object to be recycled

Referenced by sese::concurrent::ObjectPool< T >::borrow().

Member Data Documentation

◆ queue


The documentation for this class was generated from the following file: