]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
WorkQueue: add a workqueue which simply runs queued GenContexts
authorSamuel Just <sam.just@inktank.com>
Sat, 14 Sep 2013 02:49:17 +0000 (19:49 -0700)
committerSamuel Just <sam.just@inktank.com>
Thu, 26 Sep 2013 18:21:11 +0000 (11:21 -0700)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/WorkQueue.h

index b2742accdce08e31d7b395973bfeacd0cdf3a641..794b577a71dabc828071f4999ec0fc16bb61f7e2 100644 (file)
@@ -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