From f6500f59756adc953501bb517f7ec616ab490f60 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Thu, 28 Feb 2013 10:06:44 -0800 Subject: [PATCH] Context: allow C_Contexts to not have a cct, add list_to_context This will simplify the SnapMapper implementation. Signed-off-by: Samuel Just --- src/include/Context.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/include/Context.h b/src/include/Context.h index a64bb2de5f669..f2416a075d6f3 100644 --- a/src/include/Context.h +++ b/src/include/Context.h @@ -67,12 +67,14 @@ inline void finish_contexts(CephContext *cct, std::list& finished, list ls; ls.swap(finished); // swap out of place to avoid weird loops - mydout(cct, 10) << ls.size() << " contexts to finish with " << result << dendl; + if (cct) + mydout(cct, 10) << ls.size() << " contexts to finish with " << result << dendl; for (std::list::iterator it = ls.begin(); it != ls.end(); it++) { Context *c = *it; - mydout(cct,10) << "---- " << c << dendl; + if (cct) + mydout(cct,10) << "---- " << c << dendl; c->complete(result); } } @@ -86,12 +88,14 @@ inline void finish_contexts(CephContext *cct, std::vector& finished, vector ls; ls.swap(finished); // swap out of place to avoid weird loops - mydout(cct,10) << ls.size() << " contexts to finish with " << result << dendl; + if (cct) + mydout(cct,10) << ls.size() << " contexts to finish with " << result << dendl; for (std::vector::iterator it = ls.begin(); it != ls.end(); it++) { Context *c = *it; - mydout(cct,10) << "---- " << c << dendl; + if (cct) + mydout(cct,10) << "---- " << c << dendl; c->complete(result); } } @@ -125,9 +129,21 @@ public: finish_contexts(cct, contexts, r); } bool empty() { return contexts.empty(); } -}; - + static Context *list_to_context(list &cs) { + if (cs.size() == 0) { + return 0; + } else if (cs.size() == 1) { + Context *c = cs.front(); + cs.clear(); + return c; + } else { + C_Contexts *c(new C_Contexts(0)); + c->take(cs); + return c; + } + } +}; /* -- 2.39.5