19#ifndef FASTRTPS_UTILS_PROXY_POOL_HPP_
20#define FASTRTPS_UTILS_PROXY_POOL_HPP_
25#include <condition_variable>
29#if defined(__has_include) && __has_include(<version>)
39#if defined(__cpp_lib_integer_sequence) \
40 && ((__cpp_lib_integer_sequence <= _MSVC_LANG) \
41 || (__cpp_lib_integer_sequence <= __cplusplus))
44template<
class P,
size_t... Ints>
45std::array<P,
sizeof...(Ints)> make_array(
47 std::index_sequence<Ints...> is)
49 return { (Ints == is.size() - 1 ? std::move(i) : i)...};
52template<
size_t N,
class P>
53std::array<P, N> make_array(
56 return make_array<P>(std::move(i), std::make_index_sequence<N>{});
61template<
size_t N,
class P,
class ... Ts>
62std::array<P, N> make_array(
66template<bool,
size_t N,
class ... Ts>
67struct make_array_choice
70 static std::array<P, N> res(
75 return make_array<N>(std::move(i), std::move(tmp), std::move(args)...);
80template<
size_t N,
class ... Ts>
81struct make_array_choice<true, N, Ts...>
84 static std::array<P, N> res(
88 return {std::move(i), std::move(args)...};
93template<
size_t N,
class P,
class ... Ts>
94std::array<P, N> make_array(
98 return make_array_choice < N == (
sizeof...(Ts) + 1), N, Ts ... > ::res(std::move(i), std::move(args)...);
105template<
class Proxy, std::
size_t N = 4>
108 mutable std::mutex mtx_;
109 std::condition_variable cv_;
110 std::array<Proxy, N> heap_;
111 std::bitset<N> mask_;
148 std::size_t idx = p - heap_.data();
150 std::lock_guard<std::mutex> _(mtx_);
153 assert(!mask_.test(idx));
172 : heap_(make_array<N>(std::move(init)))
185 std::unique_lock<std::mutex> lock(mtx_);
196 static constexpr std::size_t
size()
207 std::lock_guard<std::mutex> _(mtx_);
208 return mask_.count();
217 std::unique_ptr<Proxy, D&>
get()
219 std::unique_lock<std::mutex> lock(mtx_);
229 while (idx < mask_.size() && !mask_.test(idx))
236 return std::unique_ptr<Proxy, D&>(&heap_[idx], deleter_);
Definition ProxyPool.hpp:107
std::unique_ptr< Proxy, D & > smart_ptr
Definition ProxyPool.hpp:164
static constexpr std::size_t size()
Definition ProxyPool.hpp:196
friend class D
Definition ProxyPool.hpp:139
std::unique_ptr< Proxy, D & > get()
Definition ProxyPool.hpp:217
std::size_t available() const noexcept
Definition ProxyPool.hpp:205
~ProxyPool()
Definition ProxyPool.hpp:183
ProxyPool(Proxy &&init)
Definition ProxyPool.hpp:170
eProsima namespace.
Definition LibrarySettingsAttributes.h:23