From: Loic Dachary Date: Tue, 13 Aug 2013 14:40:06 +0000 (+0200) Subject: ReplicatedPG: replace map iterators with SharedPtrRegistry::get_next X-Git-Tag: v0.69~76^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=833a225008115ef87884791dafa3797dbae9f9fd;p=ceph.git ReplicatedPG: replace map iterators with SharedPtrRegistry::get_next SharedPtrRegistry does not provide an iterator equivalent to map::iterator i It is replaced with a thread safe get_next method roughly used as follows: pair i; while (object_contexts.get_next(i.first, &i)) All occurences of the iterator are replaced with get_next style traversal. http://tracker.ceph.com/issues/5510 refs #5510 Signed-off-by: Loic Dachary --- diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 54d5d3a22650..6c81997c9314 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -4329,11 +4329,10 @@ void ReplicatedPG::repop_ack(RepGather *repop, int result, int ack_type, void ReplicatedPG::get_watchers(list &pg_watchers) { - for (map::iterator i = object_contexts.begin(); - i != object_contexts.end(); - ++i) { - i->second->get(); - get_obc_watchers(i->second, pg_watchers); + pair i; + while (object_contexts.get_next(i.first, &i)) { + ObjectContextRef obc(i.second); + get_obc_watchers(obc, pg_watchers); } } @@ -4361,12 +4360,9 @@ void ReplicatedPG::get_obc_watchers(ObjectContextRef obc, list void ReplicatedPG::check_blacklisted_watchers() { dout(20) << "ReplicatedPG::check_blacklisted_watchers for pg " << get_pgid() << dendl; - for (map::iterator i = object_contexts.begin(); - i != object_contexts.end(); - ++i) { - i->second->get(); - check_blacklisted_obc_watchers(i->second); - } + pair i; + while (object_contexts.get_next(i.first, &i)) + check_blacklisted_obc_watchers(i.second); } void ReplicatedPG::check_blacklisted_obc_watchers(ObjectContextRef obc) @@ -4546,23 +4542,18 @@ ObjectContextRef ReplicatedPG::get_object_context(const hobject_t& soid, void ReplicatedPG::context_registry_on_change() { - list contexts; - for (map::iterator i = object_contexts.begin(); - i != object_contexts.end(); - ++i) { - i->second->get(); - contexts.push_back(i->second); - for (map, WatchRef>::iterator j = - i->second->watchers.begin(); - j != i->second->watchers.end(); - i->second->watchers.erase(j++)) { - j->second->discard(); + pair i; + while (object_contexts.get_next(i.first, &i)) { + ObjectContextRef obc(i.second); + if (obc) { + for (map, WatchRef>::iterator j = + obc->watchers.begin(); + j != obc->watchers.end(); + obc->watchers.erase(j++)) { + j->second->discard(); + } } } - for (list::iterator i = contexts.begin(); - i != contexts.end(); - contexts.erase(i++)) { - } }