|
arrp 0.0.15
Auto returning resource pool for modern C++
|
Thread-safe auto-returning resource pool for modern C++. More...
#include <siddiqsoft/resource_pool.hpp>
Public Types | |
| enum class | auto_add_policy { NoGrow , AutoGrow } |
| This controls the auto-grow (or adding items when the pool is starving) and below capacity (up to the maximum limit). The load is calculated as. More... | |
Public Member Functions | |
| resource_pool (std::function< SRT(resource_pool &)> &&new_resource_callback) | |
| resource_pool (auto_add_policy add_policy=auto_add_policy::NoGrow) | |
| This is the default constructor.. the policy is to not auto-grow. The client code can as for AutoGrow in which case we will use the lambda to get the derived-class to build its custom pool. | |
| resource_pool (resource_pool &)=delete | |
| Copy constructor is deleted. | |
| resource_pool (resource_pool &&src)=delete | |
| Move constructor is deleted. | |
| resource_pool & | operator= (resource_pool &)=delete |
| Copy assignment operator is deleted. | |
| resource_pool & | operator= (resource_pool &&src)=delete |
| Move assignment operator is deleted. | |
| ~resource_pool () | |
| Destructor - clears all resources from the pool. | |
| void | clear () noexcept |
| size_t | size () const noexcept |
| auto | checkout () -> SRT |
| void | checkin (T &&raw_resource) |
Static Public Attributes | |
| static std::function< SRT(resource_pool &)> | CallbackDoNotAutoAddResource |
| This callback is the default and does not grow the resource; it throws a runtime_error. | |
Thread-safe auto-returning resource pool for modern C++.
| T | The resource type to be pooled. Must be move-constructible and non-arithmetic. |
| SRT | The scoped resource wrapper type. Defaults to scoped_resource<T>. |
| InitCapacity | The initial capacity of the pool. Defaults to resource_pool_limits::DefaultCapacity. |
The resource_pool class implements a thread-safe object pool pattern with automatic resource management using RAII principles. Resources are automatically returned to the pool when the scoped_resource wrapper goes out of scope, eliminating manual resource management and reducing the risk of resource leaks.
Key Features:
Usage Example:
Thread Safety:
Constraints:
Definition at line 123 of file resource_pool.hpp.
|
strong |
This controls the auto-grow (or adding items when the pool is starving) and below capacity (up to the maximum limit). The load is calculated as.
Definition at line 179 of file resource_pool.hpp.
|
inline |
Definition at line 223 of file resource_pool.hpp.
|
inline |
This is the default constructor.. the policy is to not auto-grow. The client code can as for AutoGrow in which case we will use the lambda to get the derived-class to build its custom pool.
Definition at line 237 of file resource_pool.hpp.
References CallbackDoNotAutoAddResource.
|
inline |
Destructor - clears all resources from the pool.
Invokes the pool shutdown callback if registered, then clears all remaining resources from the pool. Any resources that are currently checked out are NOT affected by this operation.
Definition at line 285 of file resource_pool.hpp.
|
inline |
Definition at line 486 of file resource_pool.hpp.
|
inlinenodiscard |
Definition at line 377 of file resource_pool.hpp.
|
inlinenoexcept |
Definition at line 305 of file resource_pool.hpp.
|
inlinenodiscardnoexcept |
Definition at line 334 of file resource_pool.hpp.
|
inlinestatic |
This callback is the default and does not grow the resource; it throws a runtime_error.
Definition at line 186 of file resource_pool.hpp.
Referenced by resource_pool().