AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::ResourcePoolState< T > Struct Template Reference

Resource pool shared state (internal usage). More...

#include <resourcePool.hpp>

Collaboration diagram for anch::ResourcePoolState< T >:

Public Member Functions

void release (std::shared_ptr< T > res, bool valid) noexcept
void notifyFirstWaiter () noexcept

Public Attributes

std::mutex _mutex
std::deque< std::condition_variable * > _waiters
std::deque< std::shared_ptr< T > > _availables
std::size_t _used = 0
bool _closed = false

Detailed Description

template<anch::Validable T>
struct anch::ResourcePoolState< T >

Resource pool shared state (internal usage).

State shared between ResourcePool and its borrowed PoolableResource.
It is kept alive by borrowed resources: a resource can be released after its pool destruction.
Every member is protected by _mutex.

Author
Vincent Lachenal
Since
0.1

Member Function Documentation

◆ notifyFirstWaiter()

template<anch::Validable T>
void anch::ResourcePoolState< T >::notifyFirstWaiter ( )
noexcept

Wake up the first waiting borrower (_mutex has to be locked)

◆ release()

template<anch::Validable T>
void anch::ResourcePoolState< T >::release ( std::shared_ptr< T > res,
bool valid )
noexcept

Release a borrowed resource slot.
Valid resource is pushed back in pool (unless the pool has been destroyed) ; invalid one is destroyed.
Resources are destroyed outside the lock.

Parameters
resthe resource (can be nullptr when its creation has failed)
validtrue if the resource can be reused, false otherwise

Member Data Documentation

◆ _availables

template<anch::Validable T>
std::deque<std::shared_ptr<T> > anch::ResourcePoolState< T >::_availables

Available resources

◆ _closed

template<anch::Validable T>
bool anch::ResourcePoolState< T >::_closed = false

true when the pool has been destroyed

◆ _mutex

template<anch::Validable T>
std::mutex anch::ResourcePoolState< T >::_mutex

State mutex

◆ _used

template<anch::Validable T>
std::size_t anch::ResourcePoolState< T >::_used = 0

Number of borrowed resources (including resources which are being created)

◆ _waiters

template<anch::Validable T>
std::deque<std::condition_variable*> anch::ResourcePoolState< T >::_waiters

Borrowers waiting for a resource, in arrival order: each one waits on its own condition variable and only the first one is woken up (borrowers are served in FIFO order)


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