# HG changeset patch # Parent 0a2945711797ba2be55e38f33df21f561ad14560 # User Zack Weinberg pyviz.cc needs to use ScheduleWithContext instead of Schedule for thread safety diff --git a/src/visualizer/model/pyviz.cc b/src/visualizer/model/pyviz.cc --- a/src/visualizer/model/pyviz.cc +++ b/src/visualizer/model/pyviz.cc @@ -310,20 +310,26 @@ PyViz::SimulatorRunUntil (Time time) if (Simulator::Now () >= time) { return; } // Schedule a dummy callback function for the target time, to make // sure we stop at the right time. Otherwise, simulations with few // events just appear to "jump" big chunks of time. - NS_LOG_LOGIC ("Schedule dummy callback to be called in " << (time - Simulator::Now ())); + NS_LOG_LOGIC ("Schedule dummy callback to be called in " + << (time - Simulator::Now ())); m_stop = false; - Simulator::Cancel (m_stopCallbackEvent); - m_stopCallbackEvent = Simulator::Schedule (time - Simulator::Now (), &PyViz::CallbackStopSimulation, this); + if (m_stopEvent) + { + m_stopEvent->Cancel (); + } + m_stopEvent = MakeEvent (&PyViz::CallbackStopSimulation, this); + Simulator::ScheduleWithContext (0, time - Simulator::Now (), + PeekPointer (m_stopEvent)); Ptr impl = Simulator::GetImplementation (); Ptr visualImpl = DynamicCast (impl); if (visualImpl) { visualImpl->RunRealSimulator (); } else diff --git a/src/visualizer/model/pyviz.h b/src/visualizer/model/pyviz.h --- a/src/visualizer/model/pyviz.h +++ b/src/visualizer/model/pyviz.h @@ -19,17 +19,17 @@ * Python is too slow at). * * Author: Gustavo Carneiro */ #ifndef NS3_PYVIZ_H #define NS3_PYVIZ_H #include "ns3/nstime.h" -#include "ns3/event-id.h" +#include "ns3/event-impl.h" #include "ns3/node.h" #include "ns3/channel.h" #include "ns3/packet.h" #include "ns3/mac48-address.h" #include "ns3/ipv4-header.h" #include "ns3/ipv4-l3-protocol.h" #include @@ -215,16 +215,16 @@ private: void TraceNetDevTxLte (std::string context, Ptr packet, Mac48Address const &destination); void TraceNetDevRxLte (std::string context, Ptr packet, Mac48Address const &source); inline NetDeviceStatistics & FindNetDeviceStatistics (int node, int interface); void DoPause (std::string const &message); bool m_stop; - EventId m_stopCallbackEvent; + Ptr m_stopEvent; void CallbackStopSimulation (); }; } #endif /* NS3_PYVIZ_H */