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

Implements a resource pool that stores objects of type T. Said objects can be shared_ptr or unique_ptr Client "acquire" and "release" T from this pool. The capacity of this pool should be kept at the same value as std::thread::hardware_concurrency(). More...

#include </opt/azure-agent/_work/14/s/include/siddiqsoft/resource_pool.hpp>

Public Member Functions

 resource_pool (resource_pool &)=delete
 resource_pool (resource_pool &&src)=default
resource_pool & operator= (resource_pool &)=delete
resource_pool & operator= (resource_pool &&src)=default
void clear ()
 Clear all items from the pool FIX: Removed unnecessary empty check - clear() is safe on empty deque.
auto size ()
 Get the current size of the pool FIX: Removed unnecessary empty check - return size unconditionally This prevents TOCTOU (Time-of-Check-Time-of-Use) race condition.
checkout ()
void checkin (T &&rsrc)
 Insert a new element or return a borrowed element.

Detailed Description

template<typename T>
requires std::move_constructible<T>
class siddiqsoft::resource_pool< T >

Implements a resource pool that stores objects of type T. Said objects can be shared_ptr or unique_ptr Client "acquire" and "release" T from this pool. The capacity of this pool should be kept at the same value as std::thread::hardware_concurrency().

Template Parameters
TThe storage element type. Maybe shared_ptr or unique_ptr The only requirement is that the underlying object is move-constructible!

Definition at line 60 of file resource_pool.hpp.

Constructor & Destructor Documentation

◆ ~resource_pool()

template<typename T>
siddiqsoft::resource_pool< T >::~resource_pool ( )
inline

Definition at line 73 of file resource_pool.hpp.

Member Function Documentation

◆ checkin()

template<typename T>
void siddiqsoft::resource_pool< T >::checkin ( T && rsrc)
inline

Insert a new element or return a borrowed element.

Parameters
rsrcR-Value for the item to return to the pool (previously checkout'd or create a new one!)

Definition at line 111 of file resource_pool.hpp.

◆ checkout()

template<typename T>
T siddiqsoft::resource_pool< T >::checkout ( )
inlinenodiscard

Definition at line 95 of file resource_pool.hpp.

◆ clear()

template<typename T>
void siddiqsoft::resource_pool< T >::clear ( )
inline

Clear all items from the pool FIX: Removed unnecessary empty check - clear() is safe on empty deque.

Definition at line 80 of file resource_pool.hpp.

◆ size()

template<typename T>
auto siddiqsoft::resource_pool< T >::size ( )
inline

Get the current size of the pool FIX: Removed unnecessary empty check - return size unconditionally This prevents TOCTOU (Time-of-Check-Time-of-Use) race condition.

Definition at line 89 of file resource_pool.hpp.


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