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))
44 template<
class P,
size_t... Ints>
45 std::array<P,
sizeof...(Ints)> make_array(
47 std::index_sequence<Ints...> is)
49 return { (Ints == is.size() - 1 ? std::move(i) : i)...};
52 template<
size_t N,
class P>
53 std::array<P, N> make_array(
56 return make_array<P>(std::move(i), std::make_index_sequence<N>{});
61 template<
size_t N,
class P,
class ... Ts>
62 std::array<P, N> make_array(
66 template<bool,
size_t N,
class ... Ts>
67 struct make_array_choice
70 static std::array<P, N> res(
75 return make_array<N>(std::move(i), std::move(tmp), std::move(args)...);
80 template<
size_t N,
class ... Ts>
81 struct make_array_choice<true, N, Ts...>
84 static std::array<P, N> res(
88 return {std::move(i), std::move(args)...};
93 template<
size_t N,
class P,
class ... Ts>
94 std::array<P, N> make_array(
98 return make_array_choice < N == (
sizeof...(Ts) + 1), N, Ts ... > ::res(std::move(i), std::move(args)...);
105 template<
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));
169 : heap_(make_array<N>(std::move(init)))
182 std::unique_lock<std::mutex> lock(mtx_);
193 static constexpr std::size_t
size()
204 std::lock_guard<std::mutex> _(mtx_);
205 return mask_.count();
214 std::unique_ptr<Proxy, D&>
get()
216 std::unique_lock<std::mutex> lock(mtx_);
226 while (idx < mask_.size() && !mask_.test(idx))
233 return std::unique_ptr<Proxy, D&>(&heap_[idx], deleter_);
Definition: ProxyPool.hpp:107
std::unique_ptr< Proxy, D & > get()
Definition: ProxyPool.hpp:214
std::unique_ptr< Proxy, D & > smart_ptr
Definition: ProxyPool.hpp:161
static constexpr std::size_t size()
Definition: ProxyPool.hpp:193
friend class D
Definition: ProxyPool.hpp:139
std::size_t available() const noexcept
Definition: ProxyPool.hpp:202
~ProxyPool()
Definition: ProxyPool.hpp:180
ProxyPool(Proxy &&init)
Definition: ProxyPool.hpp:167
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23