Index: src/simulator/realtime-simulator-impl.cc |
=================================================================== |
--- a/src/simulator/realtime-simulator-impl.cc |
+++ b/src/simulator/realtime-simulator-impl.cc |
@@ -31,6 +31,7 @@ |
#include "ns3/system-mutex.h" |
#include "ns3/boolean.h" |
#include "ns3/enum.h" |
+#include "ns3/tls-data.h" |
#include <math.h> |
@@ -423,6 +424,8 @@ |
NS_ASSERT_MSG (m_running == false, |
"RealtimeSimulatorImpl::Run(): Simulator already running"); |
+ TlsSetInRun (true); |
+ |
m_stop = false; |
m_running = true; |
m_synchronizer->SetOrigin (m_currentTs); |
@@ -465,6 +468,8 @@ |
} |
m_running = false; |
+ |
+ TlsSetInRun (false); |
} |
bool |
@@ -501,6 +506,8 @@ |
NS_ASSERT_MSG (m_running == false, |
"RealtimeSimulatorImpl::RunOneEvent(): An internal simulator event loop is running"); |
+ TlsSetInRun (true); |
+ |
EventImpl *event = 0; |
// |
@@ -523,6 +530,8 @@ |
} |
event->Invoke (); |
event->Unref (); |
+ |
+ TlsSetInRun (false); |
} |
void |
@@ -580,6 +589,19 @@ |
CriticalSection cs (m_mutex); |
uint64_t ts; |
+ if (TlsIsInRun ()) |
+ { |
+ ts = m_currentTs + time.GetTimeStep (); |
+ } |
+ else |
+ { |
+ // |
+ // If the simulator is running, we're pacing and have a meaningful |
+ // realtime clock. If we're not, then m_currentTs is were we stopped. |
+ // |
+ ts = m_running ? m_synchronizer->GetCurrentRealtime () : m_currentTs; |
+ ts += time.GetTimeStep (); |
+ } |
ts = m_currentTs + time.GetTimeStep (); |
NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs"); |
Scheduler::Event ev; |