Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(758)

Unified Diff: src/simulator/realtime-simulator-impl.cc

Issue 2334041: thread-safe implementation of ScheduleWithContext
Patch Set: Created 13 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/simulator/default-simulator-impl.cc ('k') | src/simulator/tls-data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/simulator/default-simulator-impl.cc ('k') | src/simulator/tls-data.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b