VLink  2.0.0
A high-performance communication middleware
vlink::ObjectPoolBase Class Reference

Type-independent base of ObjectPool that owns counters, mutex and policy state. More...

#include <object_pool.h>

Inheritance diagram for vlink::ObjectPoolBase:
Collaboration diagram for vlink::ObjectPoolBase:

Classes

struct  Stats
 Point-in-time snapshot of internal pool counters. More...
 

Public Types

enum  Policy : uint8_t { kPolicyNone = 0 , kPolicyRelease = 1 , kPolicyAcquire = 2 , kPolicyBoth = 3 }
 Decides when (or whether) the user-supplied ResetCallback runs. More...
 

Public Member Functions

size_t borrowed () const
 Returns the number of objects currently checked out of the pool. More...
 
size_t total_created () const
 Returns the cumulative number of objects ever produced by the factory. More...
 
size_t max_size () const noexcept
 Returns the configured upper bound on live objects. More...
 

Protected Member Functions

 ObjectPoolBase (size_t max_size, size_t initial_size, Policy policy)
 
 ~ObjectPoolBase () noexcept=default
 
void safe_dec_borrowed_and_live () noexcept
 
bool should_reset_on_acquire () const noexcept
 
bool should_reset_on_release () const noexcept
 
void throw_exhausted (size_t pool_size) const
 

Static Protected Member Functions

static void throw_invalid_size ()
 
static void throw_factory_null_pre_fill ()
 
static void throw_factory_null ()
 

Protected Attributes

Policy policy_ {kPolicyNone}
 
size_t max_size_ {0}
 
std::mutex mutex_
 
size_t borrowed_ {0}
 
size_t live_count_ {0}
 
size_t total_created_ {0}
 

Detailed Description

Type-independent base of ObjectPool that owns counters, mutex and policy state.

Keeps the shared bookkeeping for ObjectPool<T> in a single translation unit so that cold-path validation and error-throwing helpers do not need to be re-instantiated for every element type. Element storage and callbacks remain in the derived template.

Member Enumeration Documentation

◆ Policy

Decides when (or whether) the user-supplied ResetCallback runs.

Reset failures on the release path are caught and the offending object is dropped from the pool instead of being recycled. Failures on the acquire path are rethrown after the object has been put back on the free list.

Enumerator
kPolicyNone 

Never invoke the reset callback.

kPolicyRelease 

Reset on the return-to-pool path.

kPolicyAcquire 

Reset on the hand-out-to-caller path.

kPolicyBoth 

Reset on both paths.

Constructor & Destructor Documentation

◆ ObjectPoolBase()

vlink::ObjectPoolBase::ObjectPoolBase ( size_t  max_size,
size_t  initial_size,
Policy  policy 
)
protected

◆ ~ObjectPoolBase()

vlink::ObjectPoolBase::~ObjectPoolBase ( )
protecteddefaultnoexcept

Member Function Documentation

◆ borrowed()

size_t vlink::ObjectPoolBase::borrowed ( ) const

Returns the number of objects currently checked out of the pool.

Returns
Borrowed object count.

◆ max_size()

size_t vlink::ObjectPoolBase::max_size ( ) const
noexcept

Returns the configured upper bound on live objects.

Returns
Maximum size; 0 means unlimited.

◆ safe_dec_borrowed_and_live()

void vlink::ObjectPoolBase::safe_dec_borrowed_and_live ( )
protectednoexcept

◆ should_reset_on_acquire()

bool vlink::ObjectPoolBase::should_reset_on_acquire ( ) const
protectednoexcept

◆ should_reset_on_release()

bool vlink::ObjectPoolBase::should_reset_on_release ( ) const
protectednoexcept
Here is the caller graph for this function:

◆ throw_exhausted()

void vlink::ObjectPoolBase::throw_exhausted ( size_t  pool_size) const
protected

◆ throw_factory_null()

static void vlink::ObjectPoolBase::throw_factory_null ( )
staticprotected

◆ throw_factory_null_pre_fill()

static void vlink::ObjectPoolBase::throw_factory_null_pre_fill ( )
staticprotected
Here is the caller graph for this function:

◆ throw_invalid_size()

static void vlink::ObjectPoolBase::throw_invalid_size ( )
staticprotected

◆ total_created()

size_t vlink::ObjectPoolBase::total_created ( ) const

Returns the cumulative number of objects ever produced by the factory.

Returns
Total created count.

Member Data Documentation

◆ borrowed_

size_t vlink::ObjectPoolBase::borrowed_ {0}
protected

◆ live_count_

size_t vlink::ObjectPoolBase::live_count_ {0}
protected

◆ max_size_

size_t vlink::ObjectPoolBase::max_size_ {0}
protected

◆ mutex_

std::mutex vlink::ObjectPoolBase::mutex_
mutableprotected

◆ policy_

Policy vlink::ObjectPoolBase::policy_ {kPolicyNone}
protected

◆ total_created_

size_t vlink::ObjectPoolBase::total_created_ {0}
protected

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