0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 00:14:07 +01:00

ircd::ctx: Add allocator to ctx::queue template.

This commit is contained in:
Jason Volk 2019-02-28 10:59:10 -08:00
parent 5e8fce2a40
commit 54224e9679

View file

@ -13,14 +13,17 @@
namespace ircd::ctx
{
template<class T> class queue;
template<class T,
class A = std::allocator<T>>
class queue;
}
template<class T>
template<class T,
class A>
class ircd::ctx::queue
{
dock d;
std::deque<T> q;
std::deque<T, A> q;
size_t w {0};
public:
@ -38,46 +41,66 @@ class ircd::ctx::queue
void push(const T &);
void push(T &&) noexcept;
queue() = default;
queue();
queue(A&& alloc);
~queue() noexcept;
};
template<class T>
ircd::ctx::queue<T>::~queue()
template<class T,
class A>
ircd::ctx::queue<T, A>::queue()
:q(std::allocator<T>())
{
}
template<class T,
class A>
ircd::ctx::queue<T, A>::queue(A&& alloc)
:q(std::forward<A>(alloc))
{
}
template<class T,
class A>
ircd::ctx::queue<T, A>::~queue()
noexcept
{
assert(q.empty());
}
template<class T>
template<class T,
class A>
void
ircd::ctx::queue<T>::push(T&& t)
ircd::ctx::queue<T, A>::push(T&& t)
noexcept
{
q.push_back(std::forward<T>(t));
d.notify();
}
template<class T>
template<class T,
class A>
void
ircd::ctx::queue<T>::push(const T &t)
ircd::ctx::queue<T, A>::push(const T &t)
{
q.push_back(t);
d.notify();
}
template<class T>
template<class T,
class A>
template<class... args>
void
ircd::ctx::queue<T>::emplace(args&&... a)
ircd::ctx::queue<T, A>::emplace(args&&... a)
{
q.emplace(std::forward<args>(a)...);
d.notify();
}
template<class T>
template<class T,
class A>
T
ircd::ctx::queue<T>::pop()
ircd::ctx::queue<T, A>::pop()
{
++w;
const unwind uw{[this]
@ -96,10 +119,11 @@ ircd::ctx::queue<T>::pop()
return ret;
}
template<class T>
template<class T,
class A>
template<class duration>
T
ircd::ctx::queue<T>::pop_for(const duration &dur)
ircd::ctx::queue<T, A>::pop_for(const duration &dur)
{
++w;
const unwind uw{[this]
@ -124,10 +148,11 @@ ircd::ctx::queue<T>::pop_for(const duration &dur)
return ret;
}
template<class T>
template<class T,
class A>
template<class time_point>
T
ircd::ctx::queue<T>::pop_until(time_point&& tp)
ircd::ctx::queue<T, A>::pop_until(time_point&& tp)
{
++w;
const unwind uw{[this]
@ -152,25 +177,28 @@ ircd::ctx::queue<T>::pop_until(time_point&& tp)
return ret;
}
template<class T>
template<class T,
class A>
size_t
ircd::ctx::queue<T>::waiting()
ircd::ctx::queue<T, A>::waiting()
const
{
return w;
}
template<class T>
template<class T,
class A>
size_t
ircd::ctx::queue<T>::size()
ircd::ctx::queue<T, A>::size()
const
{
return q.size();
}
template<class T>
template<class T,
class A>
size_t
ircd::ctx::queue<T>::empty()
ircd::ctx::queue<T, A>::empty()
const
{
return q.empty();