bug 1000: Make RealtimeSimulatorImpl last until stop

This commit is contained in:
Mathieu Lacage
2012-03-26 06:13:16 -04:00
parent 9691d018e8
commit db064e1f69
2 changed files with 22 additions and 14 deletions

View File

@@ -113,6 +113,7 @@ main (int argc, char *argv[])
//
// Now, do the actual simulation.
//
Simulator::Stop (Seconds (11.0));
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();

View File

@@ -433,27 +433,34 @@ RealtimeSimulatorImpl::Run (void)
m_running = true;
m_synchronizer->SetOrigin (m_currentTs);
for (;;)
// Sleep until signalled
uint64_t tsNow;
uint64_t tsDelay = 1000000000; // wait time of 1 second (in nanoseconds)
while (!m_stop)
{
bool done = false;
bool process = false;
{
CriticalSection cs (m_mutex);
//
// In all cases we stop when the event list is empty. If you are doing a
// realtime simulation and you want it to extend out for some time, you must
// call StopAt. In the realtime case, this will stick a placeholder event out
// at the end of time.
//
if (m_stop || m_events->IsEmpty ())
if (!m_events->IsEmpty ())
{
done = true;
process = true;
}
else
{
// Get current timestamp while holding the critical section
tsNow = m_synchronizer->GetCurrentRealtime ();
}
}
if (done)
if (!process)
{
break;
// Sleep until signalled
tsNow = m_synchronizer->Synchronize (tsNow, tsDelay);
// Re-check event queue
continue;
}
ProcessOneEvent ();