0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 16:34:13 +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 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 class ircd::ctx::queue
{ {
dock d; dock d;
std::deque<T> q; std::deque<T, A> q;
size_t w {0}; size_t w {0};
public: public:
@ -38,46 +41,66 @@ class ircd::ctx::queue
void push(const T &); void push(const T &);
void push(T &&) noexcept; void push(T &&) noexcept;
queue() = default; queue();
queue(A&& alloc);
~queue() noexcept; ~queue() noexcept;
}; };
template<class T> template<class T,
ircd::ctx::queue<T>::~queue() 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 noexcept
{ {
assert(q.empty()); assert(q.empty());
} }
template<class T> template<class T,
class A>
void void
ircd::ctx::queue<T>::push(T&& t) ircd::ctx::queue<T, A>::push(T&& t)
noexcept noexcept
{ {
q.push_back(std::forward<T>(t)); q.push_back(std::forward<T>(t));
d.notify(); d.notify();
} }
template<class T> template<class T,
class A>
void void
ircd::ctx::queue<T>::push(const T &t) ircd::ctx::queue<T, A>::push(const T &t)
{ {
q.push_back(t); q.push_back(t);
d.notify(); d.notify();
} }
template<class T> template<class T,
class A>
template<class... args> template<class... args>
void void
ircd::ctx::queue<T>::emplace(args&&... a) ircd::ctx::queue<T, A>::emplace(args&&... a)
{ {
q.emplace(std::forward<args>(a)...); q.emplace(std::forward<args>(a)...);
d.notify(); d.notify();
} }
template<class T> template<class T,
class A>
T T
ircd::ctx::queue<T>::pop() ircd::ctx::queue<T, A>::pop()
{ {
++w; ++w;
const unwind uw{[this] const unwind uw{[this]
@ -96,10 +119,11 @@ ircd::ctx::queue<T>::pop()
return ret; return ret;
} }
template<class T> template<class T,
class A>
template<class duration> template<class duration>
T T
ircd::ctx::queue<T>::pop_for(const duration &dur) ircd::ctx::queue<T, A>::pop_for(const duration &dur)
{ {
++w; ++w;
const unwind uw{[this] const unwind uw{[this]
@ -124,10 +148,11 @@ ircd::ctx::queue<T>::pop_for(const duration &dur)
return ret; return ret;
} }
template<class T> template<class T,
class A>
template<class time_point> template<class time_point>
T T
ircd::ctx::queue<T>::pop_until(time_point&& tp) ircd::ctx::queue<T, A>::pop_until(time_point&& tp)
{ {
++w; ++w;
const unwind uw{[this] const unwind uw{[this]
@ -152,25 +177,28 @@ ircd::ctx::queue<T>::pop_until(time_point&& tp)
return ret; return ret;
} }
template<class T> template<class T,
class A>
size_t size_t
ircd::ctx::queue<T>::waiting() ircd::ctx::queue<T, A>::waiting()
const const
{ {
return w; return w;
} }
template<class T> template<class T,
class A>
size_t size_t
ircd::ctx::queue<T>::size() ircd::ctx::queue<T, A>::size()
const const
{ {
return q.size(); return q.size();
} }
template<class T> template<class T,
class A>
size_t size_t
ircd::ctx::queue<T>::empty() ircd::ctx::queue<T, A>::empty()
const const
{ {
return q.empty(); return q.empty();