add refcounting to EventImpl
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 27 Jul 2007 09:53:15 +0200
changeset 1006 489e9fc7f14f
parent 1005 43b0d2c88ab9
child 1007 3838d8b043c0
add refcounting to EventImpl
src/simulator/event-impl.cc
src/simulator/event-impl.h
--- a/src/simulator/event-impl.cc	Fri Jul 27 09:50:21 2007 +0200
+++ b/src/simulator/event-impl.cc	Fri Jul 27 09:53:15 2007 +0200
@@ -29,8 +29,24 @@
 {}
 
 EventImpl::EventImpl ()
-  : m_cancel (false)
+  : m_cancel (false),
+    m_count (1)
 {}
+void
+EventImpl::Ref (void) const
+{
+  m_count++;
+}
+void
+EventImpl::Unref (void) const
+{
+  m_count--;
+  if (m_count == 0)
+    {
+      delete this;
+    }
+}
+
 void 
 EventImpl::Invoke (void)
 {
--- a/src/simulator/event-impl.h	Fri Jul 27 09:50:21 2007 +0200
+++ b/src/simulator/event-impl.h	Fri Jul 27 09:53:15 2007 +0200
@@ -28,6 +28,8 @@
 class EventImpl {
 public:
   EventImpl ();
+  void Ref (void) const;
+  void Unref (void) const;
   virtual ~EventImpl () = 0;
   void Invoke (void);
   void Cancel (void);
@@ -37,6 +39,7 @@
 private:
   friend class Event;
   bool m_cancel;
+  mutable uint32_t m_count;
 };
 
 }; // namespace ns3