From 25cc3d73d9a69edd8ae1a67920b48de8a8a6b91f Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 8 Apr 2015 16:46:34 -0400 Subject: [PATCH 12/22] WorkQueue: add new ContextWQ work queue The queue holds a collection of Context pointers that will be completed by the thread pool. Signed-off-by: Jason Dillaman (cherry picked from commit 24a33e977f7b71962adeeb48f75d488a76e70fa9) (cherry picked from commit f28f18f6aa1930ad2cdbedb5ac7a94aafb49ed2f) --- src/common/WorkQueue.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/common/WorkQueue.h b/src/common/WorkQueue.h index cbf49a8..07aea2d 100644 --- a/src/common/WorkQueue.h +++ b/src/common/WorkQueue.h @@ -433,4 +433,35 @@ public: } }; +class ContextWQ : public ThreadPool::WorkQueueVal { +public: + ContextWQ(const string &name, time_t ti, ThreadPool *tp) + : ThreadPool::WorkQueueVal(name, ti, 0, tp) {} + + void queue(Context *ctx) { + ThreadPool::WorkQueueVal::queue(ctx); + } + +protected: + virtual void _enqueue(Context *item) { + _queue.push_back(item); + } + virtual void _enqueue_front(Context *item) { + _queue.push_front(item); + } + virtual bool _empty() { + return _queue.empty(); + } + virtual Context *_dequeue() { + Context *item = _queue.front(); + _queue.pop_front(); + return item; + } + virtual void _process(Context *item) { + item->complete(0); + } +private: + list _queue; +}; + #endif -- 2.1.0