asynchrony 2.3.1
Add asynchrony to your C++ applications using standard C++20
Loading...
Searching...
No Matches
siddiqsoft::resource_pool< T, InitCapacity > Class Template Reference

Public Member Functions

 resource_pool ()=default
 Default constructor Creates an empty pool ready to accept resources.
 resource_pool (resource_pool &)=delete
 Copy constructor (deleted - pools are not copyable) Each pool manages its own resources independently.
 resource_pool (resource_pool &&src)=default
 Move constructor (defaulted) Allows moving a pool to a new location.
resource_pooloperator= (resource_pool &)=delete
 Copy assignment operator (deleted - pools are not copyable).
resource_pooloperator= (resource_pool &&src)=default
 Move assignment operator (defaulted).
 ~resource_pool ()
 Destructor - clears all resources from the pool All remaining resources are destroyed.
void clear ()
 Clear all items from the pool.
auto size ()
 Get the current size of the pool.
auto checkout () -> resource_wrap< T >
void checkin (T &&rsrc)

Detailed Description

template<typename T, uint16_t InitCapacity = sizeof(uint8_t)>
requires ((InitCapacity <= sizeof(uint16_t))) && std::move_constructible<T>
class siddiqsoft::resource_pool< T, InitCapacity >

Definition at line 339 of file resource_pool.hpp.

Constructor & Destructor Documentation

◆ ~resource_pool()

template<typename T, uint16_t InitCapacity = sizeof(uint8_t)>
siddiqsoft::resource_pool< T, InitCapacity >::~resource_pool ( )
inline

Destructor - clears all resources from the pool All remaining resources are destroyed.

Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 371 of file resource_pool.hpp.

Member Function Documentation

◆ checkin()

template<typename T, uint16_t InitCapacity = sizeof(uint8_t)>
void siddiqsoft::resource_pool< T, InitCapacity >::checkin ( T && rsrc)
inline

Definition at line 508 of file resource_pool.hpp.

◆ checkout()

template<typename T, uint16_t InitCapacity = sizeof(uint8_t)>
auto siddiqsoft::resource_pool< T, InitCapacity >::checkout ( ) -> resource_wrap< T >
inlinenodiscard

Lambda that returns the resource back to the pool Captures 'this' to access the pool's checkin method Called by resource_wrap destructor to ensure automatic return even if an exception occurs

Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 445 of file resource_pool.hpp.

◆ clear()

template<typename T, uint16_t InitCapacity = sizeof(uint8_t)>
void siddiqsoft::resource_pool< T, InitCapacity >::clear ( )
inline

Clear all items from the pool.

Removes and destroys all resources currently in the pool. Thread-safe operation. Safe to call on an empty pool.

Note
All resources are destroyed when cleared
Any checked-out resources are NOT affected
Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 383 of file resource_pool.hpp.

◆ size()

template<typename T, uint16_t InitCapacity = sizeof(uint8_t)>
auto siddiqsoft::resource_pool< T, InitCapacity >::size ( )
inline

Get the current size of the pool.

Returns
The number of available resources currently in the pool

Returns the number of resources available for checkout. Thread-safe operation.

Note
This prevents TOCTOU (Time-of-Check-Time-of-Use) race conditions by returning the size directly without separate empty checks
Size may change immediately after this call due to concurrent access
Examples
/opt/azure-agent/_work/18/s/include/siddiqsoft/resource_pool.hpp.

Definition at line 402 of file resource_pool.hpp.


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