sim: Automatically unregister probe listeners
authorAndreas Sandberg <Andreas.Sandberg@ARM.com>
Tue, 9 Sep 2014 08:36:43 +0000 (04:36 -0400)
committerAndreas Sandberg <Andreas.Sandberg@ARM.com>
Tue, 9 Sep 2014 08:36:43 +0000 (04:36 -0400)
The ProbeListener base class automatically registers itself with a
probe manager. Currently, the class does not unregister a itself when
it is destroyed, which makes removing probes listeners somewhat
cumbersome. This patch adds an automatic call to
manager->removeListener in the ProbeListener destructor, which solves
the problem.

src/sim/probe/probe.cc
src/sim/probe/probe.hh

index 6f1a3d535c5ca5a59ab8cc9f85b4f97c177322ad..600d9dcc4bfa52237791f1fdd246680d7bbc5d3a 100644 (file)
@@ -62,11 +62,17 @@ ProbeListenerObject::~ProbeListenerObject()
     listeners.clear();
 }
 
-ProbeListener::ProbeListener(ProbeManager *manager, const std::string &name)
+ProbeListener::ProbeListener(ProbeManager *_manager, const std::string &_name)
+    : manager(_manager), name(_name)
 {
     manager->addListener(name, *this);
 }
 
+ProbeListener::~ProbeListener()
+{
+    manager->removeListener(name, *this);
+}
+
 ProbeListenerObject*
 ProbeListenerObjectParams::create()
 {
index 5a0bf11c92664eaeca394aaa784af5d47fd3027e..2946f46647b162d669dc00f5423e956d0e40b068 100644 (file)
@@ -104,7 +104,11 @@ class ProbeListener
 {
   public:
     ProbeListener(ProbeManager *manager, const std::string &name);
-    virtual ~ProbeListener() {}
+    virtual ~ProbeListener();
+
+  protected:
+    ProbeManager *const manager;
+    const std::string name;
 };
 
 /**