Commit 6a34b543 authored by Stephen Morris's avatar Stephen Morris
Browse files

[trac641] Remove callback objects's shared pointers to ZoneEntry

The ZoneEntry object was creating a callback and keeping a shared
pointer to it, but the callback was also using a shared pointer to
link back to the ZoneEntry.  This change removed the shared pointers
in the callback objects - they now use a "raw" pointer to point back
to the ZoneEntry.
parent c416ba80
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
// PERFORMANCE OF THIS SOFTWARE. // PERFORMANCE OF THIS SOFTWARE.
#include <map> #include <map>
#include <config.h> #include <config.h>
#include "zone_entry.h" #include "zone_entry.h"
...@@ -81,7 +80,7 @@ class ZoneEntry::ResolverCallback : ...@@ -81,7 +80,7 @@ class ZoneEntry::ResolverCallback :
public isc::resolve::ResolverInterface::Callback { public isc::resolve::ResolverInterface::Callback {
public: public:
/// \short Constructor. Pass "this" zone entry /// \short Constructor. Pass "this" zone entry
ResolverCallback(boost::shared_ptr<ZoneEntry> entry) : ResolverCallback(ZoneEntry* entry) :
entry_(entry) entry_(entry)
{ } { }
/** /**
...@@ -219,8 +218,9 @@ class ZoneEntry::ResolverCallback : ...@@ -219,8 +218,9 @@ class ZoneEntry::ResolverCallback :
// Process all three callback lists and tell them KO // Process all three callback lists and tell them KO
entry_->process(ADDR_REQ_MAX, NameserverPtr()); entry_->process(ADDR_REQ_MAX, NameserverPtr());
} }
/// \short The entry we are callback of // The entry we are callback of. As this object will hold a
boost::shared_ptr<ZoneEntry> entry_; // shared pointer to us, a "raw" pointer is fine here.
ZoneEntry* entry_;
}; };
void void
...@@ -255,7 +255,7 @@ ZoneEntry::addCallback(CallbackPtr callback, AddressFamily family) { ...@@ -255,7 +255,7 @@ ZoneEntry::addCallback(CallbackPtr callback, AddressFamily family) {
QuestionPtr question(new Question(Name(name_), class_code_, QuestionPtr question(new Question(Name(name_), class_code_,
RRType::NS())); RRType::NS()));
boost::shared_ptr<ResolverCallback> resolver_callback( boost::shared_ptr<ResolverCallback> resolver_callback(
new ResolverCallback(shared_from_this())); new ResolverCallback(this));
resolver_->resolve(question, resolver_callback); resolver_->resolve(question, resolver_callback);
return; return;
} }
...@@ -264,7 +264,7 @@ ZoneEntry::addCallback(CallbackPtr callback, AddressFamily family) { ...@@ -264,7 +264,7 @@ ZoneEntry::addCallback(CallbackPtr callback, AddressFamily family) {
void void
ZoneEntry::removeCallback(const CallbackPtr& callback, AddressFamily family) { ZoneEntry::removeCallback(const CallbackPtr& callback, AddressFamily family) {
Lock lock(mutex_); Lock lock(mutex_);
std::vector<boost::shared_ptr<AddressRequestCallback> >::iterator i = std::vector<boost::shared_ptr<AddressRequestCallback> >::iterator i =
callbacks_[family].begin(); callbacks_[family].begin();
for (; i != callbacks_[family].end(); ++i) { for (; i != callbacks_[family].end(); ++i) {
if (*i == callback) { if (*i == callback) {
...@@ -371,7 +371,7 @@ class ZoneEntry::NameserverCallback : public NameserverEntry::Callback { ...@@ -371,7 +371,7 @@ class ZoneEntry::NameserverCallback : public NameserverEntry::Callback {
* \param family For which address family this change is, so we * \param family For which address family this change is, so we
* do not process all the nameserves and callbacks there. * do not process all the nameserves and callbacks there.
*/ */
NameserverCallback(boost::shared_ptr<ZoneEntry> entry, AddressFamily family) : NameserverCallback(ZoneEntry* entry, AddressFamily family) :
entry_(entry), entry_(entry),
family_(family) family_(family)
{ } { }
...@@ -386,7 +386,9 @@ class ZoneEntry::NameserverCallback : public NameserverEntry::Callback { ...@@ -386,7 +386,9 @@ class ZoneEntry::NameserverCallback : public NameserverEntry::Callback {
entry_->process(family_, ns); entry_->process(family_, ns);
} }
private: private:
boost::shared_ptr<ZoneEntry> entry_; // The entry we are callback of. As this object will hold a
// shared pointer to us, a "raw" pointer is fine here.
ZoneEntry* entry_;
AddressFamily family_; AddressFamily family_;
}; };
...@@ -551,7 +553,7 @@ ZoneEntry::insertCallback(NameserverPtr ns, AddressFamily family) { ...@@ -551,7 +553,7 @@ ZoneEntry::insertCallback(NameserverPtr ns, AddressFamily family) {
insertCallback(ns, V6_ONLY); insertCallback(ns, V6_ONLY);
} else { } else {
boost::shared_ptr<NameserverCallback> callback(new NameserverCallback( boost::shared_ptr<NameserverCallback> callback(new NameserverCallback(
shared_from_this(), family)); this, family));
ns->askIP(resolver_, callback, family); ns->askIP(resolver_, callback, family);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment