diff options
author | Samuel Just <sam.just@inktank.com> | 2013-09-13 19:49:17 -0700 |
---|---|---|
committer | Samuel Just <sam.just@inktank.com> | 2013-09-26 11:21:11 -0700 |
commit | 5f44a949efdfa2367cb3f591b1838ba41c72dbe2 (patch) | |
tree | 7974aec0a68d76bd05d2e81d939492eeae8ae3f4 | |
parent | fde0f864a62af39a0854af39e4e329ff80f35cf9 (diff) | |
download | ceph-5f44a949efdfa2367cb3f591b1838ba41c72dbe2.tar.gz |
WorkQueue: add a workqueue which simply runs queued GenContexts
Signed-off-by: Samuel Just <sam.just@inktank.com>
-rw-r--r-- | src/common/WorkQueue.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/common/WorkQueue.h b/src/common/WorkQueue.h index b2742accdce..794b577a71d 100644 --- a/src/common/WorkQueue.h +++ b/src/common/WorkQueue.h @@ -390,6 +390,43 @@ public: void drain(WorkQueue_* wq = 0); }; +class GenContextWQ : + public ThreadPool::WorkQueueVal<GenContext<ThreadPool::TPHandle&>*> { + list<GenContext<ThreadPool::TPHandle&>*> _queue; +public: + GenContextWQ(const string &name, time_t ti, ThreadPool *tp) + : ThreadPool::WorkQueueVal< + GenContext<ThreadPool::TPHandle&>*>(name, ti, ti*10, tp) {} + + void _enqueue(GenContext<ThreadPool::TPHandle&> *c) { + _queue.push_back(c); + }; + void _enqueue_front(GenContext<ThreadPool::TPHandle&> *c) { + _queue.push_front(c); + } + bool _empty() { + return _queue.empty(); + } + GenContext<ThreadPool::TPHandle&> *_dequeue() { + assert(!_queue.empty()); + GenContext<ThreadPool::TPHandle&> *c = _queue.front(); + _queue.pop_front(); + return c; + } + void _process(GenContext<ThreadPool::TPHandle&> *c, ThreadPool::TPHandle &tp) { + c->complete(tp); + } +}; +class C_QueueInWQ : public Context { + GenContextWQ *wq; + GenContext<ThreadPool::TPHandle&> *c; +public: + C_QueueInWQ(GenContextWQ *wq, GenContext<ThreadPool::TPHandle &> *c) + : wq(wq), c(c) {} + void finish(int) { + wq->queue(c); + } +}; #endif |