|
Lightweight 0.20260921.0
|
#include <Pool.hpp>
Classes | |
| class | PooledDataMapper |
Public Member Functions | |
| Pool () | |
| ~Pool () noexcept | |
| Pool (Pool const &)=delete | |
| Pool & | operator= (Pool const &)=delete |
| Pool (Pool &&)=delete | |
| Pool & | operator= (Pool &&)=delete |
| PooledDataMapper | Acquire () |
| std::expected< PooledDataMapper, PoolError > | Acquire (std::chrono::milliseconds timeout) |
| PooledDataMapper | Acquire () |
| std::expected< PooledDataMapper, PoolError > | Acquire (std::chrono::milliseconds timeout) |
| Async::Task< PooledDataMapper > | AcquireAsync (Async::IExecutor &dbWorkers, Async::IResumeScheduler &resume) |
| void | SetAsyncExecutors (Async::IExecutor &dbWorkers, Async::IResumeScheduler &resume) noexcept |
| Async::Task< PooledDataMapper > | AcquireAsync () |
| void | SetClock (std::function< Clock::time_point()> clock) noexcept |
A thread-safe pool of DataMapper instances with the policy configured by the PoolConfig template parameter. The pool allows acquiring and returning DataMapper instances, and manages the lifecycle of these instances according to the specified growth strategy.
|
inlineexplicit |
|
inlinenoexcept |
Destructor. The pool manages the lifecycle of the idle data mappers; be aware that any acquired data mappers not returned to the pool are destroyed when the pool is destroyed, which may leak resources if not handled properly.
Definition at line 535 of file Pool.hpp.
References Lightweight::SqlLogger::GetLogger(), and Lightweight::SqlLogger::OnWarning().
|
inline |
Function to acquire a data mapper from the pool, the behavior of this function depends on the growth strategy this is a specific implementation for the BoundedWait strategy, which blocks until a data mapper is available if the pool is at maximum capacity
Prefer the Acquire(std::chrono::milliseconds) overload in production code: this one waits indefinitely, so an exhausted pool parks the calling thread with no diagnostic.
Definition at line 561 of file Pool.hpp.
Referenced by Lightweight::Pool< Config >::Acquire().
|
inline |
Acquires a data mapper, giving up if none becomes available within timeout.
Bounds how long an exhausted BoundedWait pool may park the calling thread, so a stuck or overloaded pool surfaces as an error the caller can act on rather than as an indefinite hang.
| timeout | How long to wait for a data mapper to be returned. A non-positive value makes this a pure try-acquire. |
timeout elapsed first. Definition at line 592 of file Pool.hpp.
References Timeout.
|
inline |
Function to acquire a data mapper from the pool, the behavior of this function depends on the growth strategy this is a specific implementation for the strategies that do not block, which always creates a new data mapper if the pool is empty, regardless of the maximum capacity
Definition at line 625 of file Pool.hpp.
References Lightweight::SqlLogger::GetLogger(), and Lightweight::SqlLogger::OnConnectionReuse().
|
inline |
Acquires a data mapper, for the strategies that never wait.
Provided so call sites can be written without knowing the strategy. These strategies create a fresh data mapper whenever no idle one is available, so the timeout can never elapse and the result always holds a value.
| timeout | Ignored; see above. |
Definition at line 652 of file Pool.hpp.
References Lightweight::Pool< Config >::Acquire().
|
inline |
Asynchronously acquires a DataMapper from the pool without blocking the calling thread.
If the pool is exhausted (BoundedWait at capacity), the awaiting coroutine is suspended and resumed — via resume — when a mapper is returned, rather than parking a thread. The acquired mapper's connection is wired for async via SqlConnection::EnableAsync(dbWorkers, resume), so the caller can immediately co_await its async methods.
| dbWorkers | The worker pool used to run the acquired mapper's blocking ODBC calls. |
| resume | The scheduler used to resume coroutines (typically the app run loop). |
|
inlinenoexcept |
Configures the executors that the no-argument AcquireAsync() overload wires acquired mappers for, so async consumers of this pool no longer repeat the executors at every call.
This is opt-in and scoped to the pool: only pools configured this way hand out async-enabled mappers via the no-arg overload; synchronous Acquire and connections outside the pool are unaffected. Unlike a process-global default, the executors' lifetime is tied to this pool, which already must outlive every acquirer.
dbWorkers and resume must outlive this pool's async use (the same contract the explicit-argument AcquireAsync overload already implies). Only references are retained. Intended to be called once during setup, before any concurrent AcquireAsync(); it is not synchronized against in-flight acquirers. | dbWorkers | The worker pool used to run acquired mappers' blocking ODBC calls. |
| resume | The scheduler used to resume coroutines (typically the app run loop). |
|
inline |
Asynchronously acquires a DataMapper using the executors previously set via SetAsyncExecutors, without blocking the calling thread.
Equivalent to the explicit-argument AcquireAsync overload with the pool's stored executors; pass the executors to that overload to override them for a single call.
| std::logic_error | if SetAsyncExecutors has not been called on this pool. |
|
inlinenoexcept |
Overrides the clock the idle-time and lifetime bounds are measured against, so eviction can be driven deterministically (from a test, or from a simulated clock) instead of by sleeping.
clock reports is the caller's business afterwards. | clock | Source of the current time; pass {} to restore the real clock. |