Lightweight 0.20260617.0
Loading...
Searching...
No Matches
Lightweight::Pool< Config > Class Template Reference

#include <Pool.hpp>

Classes

class  PooledDataMapper
 

Public Member Functions

 Pool ()
 
 ~Pool () noexcept
 
 Pool (Pool const &)=delete
 
Pooloperator= (Pool const &)=delete
 
 Pool (Pool &&)=delete
 
Pooloperator= (Pool &&)=delete
 
PooledDataMapper Acquire ()
 
PooledDataMapper Acquire ()
 
Async::Task< PooledDataMapperAcquireAsync (Async::IExecutor &dbWorkers, Async::IResumeScheduler &resume)
 
void SetAsyncExecutors (Async::IExecutor &dbWorkers, Async::IResumeScheduler &resume) noexcept
 
Async::Task< PooledDataMapperAcquireAsync ()
 

Detailed Description

template<PoolConfig Config>
class Lightweight::Pool< Config >

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.

Definition at line 61 of file Pool.hpp.

Constructor & Destructor Documentation

◆ Pool()

template<PoolConfig Config>
Lightweight::Pool< Config >::Pool ( )
inlineexplicit

Default constructor that pre-creates the initial number of data mappers and stores them in the pool No other constructors are provided, as the pool is configured at compile time via the template parameter

Definition at line 206 of file Pool.hpp.

◆ ~Pool()

template<PoolConfig Config>
Lightweight::Pool< Config >::~Pool ( )
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 216 of file Pool.hpp.

References Lightweight::SqlLogger::GetLogger(), and Lightweight::SqlLogger::OnWarning().

Member Function Documentation

◆ Acquire() [1/2]

template<PoolConfig Config>
PooledDataMapper Lightweight::Pool< Config >::Acquire ( )
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

Definition at line 239 of file Pool.hpp.

◆ Acquire() [2/2]

template<PoolConfig Config>
PooledDataMapper Lightweight::Pool< Config >::Acquire ( )
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 269 of file Pool.hpp.

◆ AcquireAsync() [1/2]

template<PoolConfig Config>
Async::Task< PooledDataMapper > Lightweight::Pool< Config >::AcquireAsync ( Async::IExecutor dbWorkers,
Async::IResumeScheduler resume 
)
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.

Parameters
dbWorkersThe worker pool used to run the acquired mapper's blocking ODBC calls.
resumeThe scheduler used to resume coroutines (typically the app run loop).
Returns
A Task yielding a pooled DataMapper.

Definition at line 295 of file Pool.hpp.

◆ SetAsyncExecutors()

template<PoolConfig Config>
void Lightweight::Pool< Config >::SetAsyncExecutors ( Async::IExecutor dbWorkers,
Async::IResumeScheduler resume 
)
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.

Warning
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.
Parameters
dbWorkersThe worker pool used to run acquired mappers' blocking ODBC calls.
resumeThe scheduler used to resume coroutines (typically the app run loop).

Definition at line 315 of file Pool.hpp.

◆ AcquireAsync() [2/2]

template<PoolConfig Config>
Async::Task< PooledDataMapper > Lightweight::Pool< Config >::AcquireAsync ( )
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.

Returns
A Task yielding a pooled DataMapper.
Exceptions
std::logic_errorif SetAsyncExecutors has not been called on this pool.

Definition at line 329 of file Pool.hpp.


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