make sure that Simulator::Cancel deals correctly with events which were already scheduled
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 May 2007 10:20:44 +0200
changeset 472 41aa5fca4f49
parent 471 c2f541e6376a
child 473 7692c5266fe6
make sure that Simulator::Cancel deals correctly with events which were already scheduled
src/simulator/event-id.cc
src/simulator/simulator.cc
src/simulator/simulator.h
--- a/src/simulator/event-id.cc	Wed May 02 09:18:18 2007 +0200
+++ b/src/simulator/event-id.cc	Wed May 02 10:20:44 2007 +0200
@@ -20,6 +20,7 @@
  */
 #include "event-id.h"
 #include "simulator.h"
+#include "event-impl.h"
 
 namespace ns3 {
 
@@ -37,7 +38,11 @@
 void 
 EventId::Cancel (void)
 {
-  Simulator::Cancel (*this);
+  if (!IsExpired ())
+    {
+      m_eventImpl->Cancel ();
+      m_eventImpl = 0;
+    }
 }
 bool 
 EventId::IsExpired (void)
--- a/src/simulator/simulator.cc	Wed May 02 09:18:18 2007 +0200
+++ b/src/simulator/simulator.cc	Wed May 02 10:20:44 2007 +0200
@@ -62,7 +62,7 @@
   void ScheduleNow (EventImpl *event);
   void ScheduleDestroy (EventImpl *event);
   void Remove (EventId ev);
-  void Cancel (EventId ev);
+  void Cancel (EventId &ev);
   bool IsExpired (EventId ev);
   void Run (void);
   Time Now (void) const;
@@ -258,10 +258,9 @@
 }
 
 void
-SimulatorPrivate::Cancel (EventId id)
+SimulatorPrivate::Cancel (EventId &id)
 {
-  EventImpl *ev = id.GetEventImpl ();
-  ev->Cancel ();
+  id.Cancel ();
 }
 
 bool
@@ -453,7 +452,7 @@
 }
 
 void
-Simulator::Cancel (EventId ev)
+Simulator::Cancel (EventId &ev)
 {
   return GetPriv ()->Cancel (ev);
 }
--- a/src/simulator/simulator.h	Wed May 02 09:18:18 2007 +0200
+++ b/src/simulator/simulator.h	Wed May 02 10:20:44 2007 +0200
@@ -485,7 +485,7 @@
   /**
    * Remove an event from the event list. 
    * This method has the same visible effect as the 
-   * ns3::Simulator::cancel method or the ns3::EventId::cancel method
+   * ns3::EventId::Cancel method
    * but its algorithmic complexity is much higher: it has often 
    * O(log(n)) complexity, sometimes O(n), sometimes worse.
    * Note that it is not possible to remove events which were scheduled
@@ -506,7 +506,7 @@
    * 
    * @param id the event to cancel
    */
-  static void Cancel (EventId id);
+  static void Cancel (EventId &id);
   /**
    * This method has O(1) complexity.
    * Note that it is not possible to test for the expiration of