]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: a coroutine util function to collect a single stack
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 30 Oct 2015 18:22:42 +0000 (11:22 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:26 +0000 (16:13 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_coroutine.cc
src/rgw/rgw_coroutine.h

index b2146f46c942062e55ef699049ad3e29dcf6f0c0..c89cd6902ecd7cd189f5bb1df70d3a4587f00c28 100644 (file)
@@ -253,6 +253,39 @@ bool RGWCoroutinesStack::collect(RGWCoroutine *op, int *ret) /* returns true if
   return false;
 }
 
+bool RGWCoroutinesStack::collect_next(RGWCoroutine *op, int *ret, RGWCoroutinesStack **collected_stack) /* returns true if found a stack to collect */
+{
+  rgw_spawned_stacks *s = (op ? &op->spawned : &spawned);
+  *ret = 0;
+  vector<RGWCoroutinesStack *> new_list;
+
+  if (collected_stack) {
+    *collected_stack = NULL;
+  }
+
+  for (vector<RGWCoroutinesStack *>::iterator iter = s->entries.begin(); iter != s->entries.end(); ++iter) {
+    RGWCoroutinesStack *stack = *iter;
+    if (!stack->is_done()) {
+      continue;
+    }
+    int r = stack->get_ret_status();
+    if (r < 0) {
+      *ret = r;
+    }
+
+    if (collected_stack) {
+      *collected_stack = stack;
+    } else {
+      stack->put();
+    }
+
+    s->entries.erase(iter);
+    return true;
+  }
+
+  return false;
+}
+
 bool RGWCoroutinesStack::collect(int *ret) /* returns true if needs to be called again */
 {
   return collect(NULL, ret);
@@ -462,6 +495,11 @@ bool RGWCoroutine::collect(int *ret) /* returns true if needs to be called again
   return stack->collect(this, ret);
 }
 
+bool RGWCoroutine::collect_next(int *ret, RGWCoroutinesStack **collected_stack) /* returns true if found a stack to collect */
+{
+  return stack->collect_next(this, ret, collected_stack);
+}
+
 int RGWCoroutine::wait(const utime_t& interval)
 {
   return stack->wait(interval);
@@ -496,7 +534,7 @@ bool RGWCoroutine::drain_children(int num_cr_left)
 {
   bool done = false;
   reenter(&drain_cr) {
-    while (num_spawned() > num_cr_left) {
+    while (num_spawned() > (size_t)num_cr_left) {
       yield wait_for_child();
       int ret;
       while (collect(&ret)) {
index c085112edd0874b2446bde1650ba718f1b1e6e42..69e11792874d37dca86b3661dfd797be8a6fd982 100644 (file)
@@ -183,6 +183,7 @@ public:
   int call(RGWCoroutine *op); /* call at the same stack we're in */
   void spawn(RGWCoroutine *op, bool wait); /* execute on a different stack */
   bool collect(int *ret); /* returns true if needs to be called again */
+  bool collect_next(int *ret, RGWCoroutinesStack **collected_stack = NULL); /* returns true if found a stack to collect */
 
   int wait(const utime_t& interval);
   bool drain_children(int num_cr_left); /* returns true if needed to be called again */
@@ -282,6 +283,7 @@ protected:
 
   void spawn(RGWCoroutine *source_op, RGWCoroutine *next_op, bool wait);
   bool collect(RGWCoroutine *op, int *ret); /* returns true if needs to be called again */
+  bool collect_next(RGWCoroutine *op, int *ret, RGWCoroutinesStack **collected_stack); /* returns true if found a stack to collect */
 public:
   RGWCoroutinesStack(CephContext *_cct, RGWCoroutinesManager *_ops_mgr, RGWCoroutine *start = NULL);