Index: src/simulator/default-simulator-impl.cc |
=================================================================== |
--- a/src/simulator/default-simulator-impl.cc |
+++ b/src/simulator/default-simulator-impl.cc |
@@ -27,6 +27,7 @@ |
#include "ns3/pointer.h" |
#include "ns3/assert.h" |
#include "ns3/log.h" |
+#include "ns3/tls-data.h" |
#include <math.h> |
@@ -127,6 +128,8 @@ |
m_currentUid = next.key.m_uid; |
next.impl->Invoke (); |
next.impl->Unref (); |
+ |
+ ProcessEventsWithContext (); |
} |
bool |
@@ -152,6 +155,9 @@ |
void |
DefaultSimulatorImpl::Run (void) |
{ |
+ TlsSetInRun (true); |
+ ProcessEventsWithContext (); |
+ |
m_stop = false; |
while (!m_events->IsEmpty () && !m_stop) |
{ |
@@ -161,12 +167,38 @@ |
// If the simulator stopped naturally by lack of events, make a |
// consistency test to check that we didn't lose any events along the way. |
NS_ASSERT(!m_events->IsEmpty () || m_unscheduledEvents == 0); |
+ |
+ TlsSetInRun (false); |
} |
void |
+DefaultSimulatorImpl::ProcessEventsWithContext (void) |
+{ |
+ m_eventsWithContextMutex.Lock (); |
+ while (!m_eventsWithContext.empty ()) |
+ { |
+ EventWithContext event = m_eventsWithContext.front (); |
+ m_eventsWithContext.pop_front (); |
+ Scheduler::Event ev; |
+ ev.impl = event.event; |
+ ev.key.m_ts = m_currentTs + event.timestamp; |
+ ev.key.m_context = event.context; |
+ ev.key.m_uid = m_uid; |
+ m_uid++; |
+ m_unscheduledEvents++; |
+ m_events->Insert (ev); |
+ } |
+ m_eventsWithContextMutex.Unlock (); |
+} |
+ |
+ |
+void |
DefaultSimulatorImpl::RunOneEvent (void) |
{ |
+ TlsSetInRun (true); |
+ ProcessEventsWithContext (); |
ProcessOneEvent (); |
+ TlsSetInRun (false); |
} |
void |
@@ -207,14 +239,27 @@ |
{ |
NS_LOG_FUNCTION (this << context << time.GetTimeStep () << m_currentTs << event); |
- Scheduler::Event ev; |
- ev.impl = event; |
- ev.key.m_ts = m_currentTs + time.GetTimeStep (); |
- ev.key.m_context = context; |
- ev.key.m_uid = m_uid; |
- m_uid++; |
- m_unscheduledEvents++; |
- m_events->Insert (ev); |
+ if (TlsIsInRun ()) |
+ { |
+ Scheduler::Event ev; |
+ ev.impl = event; |
+ ev.key.m_ts = m_currentTs + time.GetTimeStep (); |
+ ev.key.m_context = context; |
+ ev.key.m_uid = m_uid; |
+ m_uid++; |
+ m_unscheduledEvents++; |
+ m_events->Insert (ev); |
+ } |
+ else |
+ { |
+ struct EventWithContext ev; |
+ ev.context = context; |
+ ev.timestamp = time.GetTimeStep (); |
+ ev.event = event; |
+ m_eventsWithContextMutex.Lock (); |
+ m_eventsWithContext.push_back (ev); |
+ m_eventsWithContextMutex.Unlock (); |
+ } |
} |
EventId |