From: Patrick Donnelly Date: Tue, 24 Jul 2018 13:48:22 +0000 (-0700) Subject: common: make C_ContextsBase container agnostic X-Git-Tag: v14.0.1~708^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=32a3de0e6160a31cc6ddd0337d8f65b5d8cae055;p=ceph.git common: make C_ContextsBase container agnostic Signed-off-by: Patrick Donnelly --- diff --git a/src/include/Context.h b/src/include/Context.h index ec3173729ef2..a801578a598a 100644 --- a/src/include/Context.h +++ b/src/include/Context.h @@ -196,11 +196,11 @@ struct C_Lock : public Context { * ContextType must be an ancestor class of ContextInstanceType, or the same class. * ContextInstanceType must be default-constructable. */ -template +template > class C_ContextsBase : public ContextInstanceType { public: CephContext *cct; - std::list contexts; + Container contexts; C_ContextsBase(CephContext *cct_) : cct(cct_) @@ -214,23 +214,14 @@ public: void add(ContextType* c) { contexts.push_back(c); } - void take(std::list& ls) { - contexts.splice(contexts.end(), ls); - } - bool sync_complete(int r) override { - auto p = contexts.begin(); - while (p != contexts.end()) { - if ((*p)->sync_complete(r)) { - p = contexts.erase(p); - } else { - ++p; - } - } - if (contexts.empty()) { - delete this; - return true; + void take(Container& ls) { + Container c; + c.swap(ls); + if constexpr (std::is_same_v>) { + contexts.splice(contexts.end(), c); + } else { + contexts.insert(contexts.end(), c.begin(), c.end()); } - return false; } void complete(int r) override { // Neuter any ContextInstanceType custom complete(), because although @@ -242,7 +233,8 @@ public: } bool empty() { return contexts.empty(); } - static ContextType *list_to_context(list &cs) { + template + static ContextType *list_to_context(C& cs) { if (cs.size() == 0) { return 0; } else if (cs.size() == 1) {