25#include <condition_variable>
43 concept Validable =
requires(
const T& object) {
44 {
object.isValid()} -> std::convertible_to<bool>;
56 class TimeoutException: std::exception {
61 std::chrono::milliseconds _timeout;
75 TimeoutException(
const std::chrono::milliseconds& timeout,
const std::string msg)
noexcept: std::exception(),
86 virtual ~TimeoutException() {
98 virtual const char* what() const noexcept {
107 inline const std::chrono::milliseconds& getTimeout() const noexcept {
115 template<anch::Validable T, typename C, std::shared_ptr<T>(*make_ptr)(
const C&)>
116 class PoolableResource;
135 template<anch::Validable T, typename C, std::shared_ptr<T>(*make_ptr)(
const C&) = std::make_shared<T> >
138 friend class PoolableResource<T,C,make_ptr>;
146 std::condition_variable _wait;
152 std::deque<std::shared_ptr<T> > _availables;
155 std::size_t _maxSize;
158 std::atomic_size_t _used;
164 std::chrono::milliseconds _timeout;
177 ResourcePool(
const C& config,
179 std::size_t initialiSize = 0,
180 std::chrono::milliseconds timeout = std::chrono::milliseconds(100));
185 ResourcePool(
const ResourcePool&) =
delete;
194 virtual ~ResourcePool();
208 anch::PoolableResource<T,C,make_ptr> borrowResource();
216 void returnResource(std::shared_ptr<T> res);
224 void invalidateResource(std::shared_ptr<T> res);
234 void setTimeout(
const std::chrono::milliseconds timeout);
241#include "impl/resourcePool.hpp"
AnCH framework base namespace.
Definition app.hpp:28