summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Just <sam.just@inktank.com>2013-09-13 19:49:17 -0700
committerSamuel Just <sam.just@inktank.com>2013-09-19 20:04:15 -0700
commit0e49f3442a70d84bcafcf14ddefc03113d81d1fa (patch)
tree4764f0297cdf2b352632e5fd513675c3dec632ca
parentf9867dce8de8b7c1dbea3472bf4d39f32bb399e1 (diff)
downloadceph-0e49f3442a70d84bcafcf14ddefc03113d81d1fa.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.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/WorkQueue.h b/src/common/WorkQueue.h
index b2742accdce..e589b3c1463 100644
--- a/src/common/WorkQueue.h
+++ b/src/common/WorkQueue.h
@@ -390,6 +390,49 @@ public:
void drain(WorkQueue_* wq = 0);
};
+class GenContextWQ :
+ public ThreadPool::WorkQueueVal<GenContext<ThreadPool::TPHandle&>*> {
+ Mutex qlock;
+ 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),
+ qlock(name.c_str()) {}
+
+ void _enqueue(GenContext<ThreadPool::TPHandle&> *c) {
+ Mutex::Locker l(qlock);
+ _queue.push_back(c);
+ };
+ void _enqueue_front(GenContext<ThreadPool::TPHandle&> *c) {
+ Mutex::Locker l(qlock);
+ _queue.push_front(c);
+ }
+ bool _empty() {
+ Mutex::Locker l(qlock);
+ return _queue.empty();
+ }
+ GenContext<ThreadPool::TPHandle&> *_dequeue() {
+ Mutex::Locker l(qlock);
+ 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 QueueInWQ : public Context {
+ GenContextWQ *wq;
+ GenContext<ThreadPool::TPHandle&> *c;
+public:
+ QueueInWQ(GenContextWQ *wq, GenContext<ThreadPool::TPHandle &> *c)
+ : wq(wq), c(c) {}
+ void finish(int) {
+ wq->queue(c);
+ }
+};
#endif