From 54224e9679035c2034819931dc185cedfe8071ef Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 28 Feb 2019 10:59:10 -0800 Subject: [PATCH] ircd::ctx: Add allocator to ctx::queue template. --- include/ircd/ctx/queue.h | 76 +++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/include/ircd/ctx/queue.h b/include/ircd/ctx/queue.h index 7363fed4b..d5d6f0026 100644 --- a/include/ircd/ctx/queue.h +++ b/include/ircd/ctx/queue.h @@ -13,14 +13,17 @@ namespace ircd::ctx { - template class queue; + template> + class queue; } -template +template class ircd::ctx::queue { dock d; - std::deque q; + std::deque 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 -ircd::ctx::queue::~queue() +template +ircd::ctx::queue::queue() +:q(std::allocator()) +{ +} + +template +ircd::ctx::queue::queue(A&& alloc) +:q(std::forward(alloc)) +{ +} + +template +ircd::ctx::queue::~queue() noexcept { assert(q.empty()); } -template +template void -ircd::ctx::queue::push(T&& t) +ircd::ctx::queue::push(T&& t) noexcept { q.push_back(std::forward(t)); d.notify(); } -template +template void -ircd::ctx::queue::push(const T &t) +ircd::ctx::queue::push(const T &t) { q.push_back(t); d.notify(); } -template +template template void -ircd::ctx::queue::emplace(args&&... a) +ircd::ctx::queue::emplace(args&&... a) { q.emplace(std::forward(a)...); d.notify(); } -template +template T -ircd::ctx::queue::pop() +ircd::ctx::queue::pop() { ++w; const unwind uw{[this] @@ -96,10 +119,11 @@ ircd::ctx::queue::pop() return ret; } -template +template template T -ircd::ctx::queue::pop_for(const duration &dur) +ircd::ctx::queue::pop_for(const duration &dur) { ++w; const unwind uw{[this] @@ -124,10 +148,11 @@ ircd::ctx::queue::pop_for(const duration &dur) return ret; } -template +template template T -ircd::ctx::queue::pop_until(time_point&& tp) +ircd::ctx::queue::pop_until(time_point&& tp) { ++w; const unwind uw{[this] @@ -152,25 +177,28 @@ ircd::ctx::queue::pop_until(time_point&& tp) return ret; } -template +template size_t -ircd::ctx::queue::waiting() +ircd::ctx::queue::waiting() const { return w; } -template +template size_t -ircd::ctx::queue::size() +ircd::ctx::queue::size() const { return q.size(); } -template +template size_t -ircd::ctx::queue::empty() +ircd::ctx::queue::empty() const { return q.empty();