diff --git a/src/core/examples/main-test-sync.cc b/src/core/examples/main-test-sync.cc index 5aa120eed..fd0275465 100644 --- a/src/core/examples/main-test-sync.cc +++ b/src/core/examples/main-test-sync.cc @@ -97,7 +97,7 @@ FakeNetDevice::Doit3 (void) // // Exercise the realtime relative now path // - Simulator::ScheduleWithContext(0xffffffff, Seconds(0.0), MakeEvent (&inserted_function)); + Simulator::ScheduleWithContext(Simulator::NO_CONTEXT, Seconds(0.0), MakeEvent (&inserted_function)); usleep (1000); } } diff --git a/src/core/model/default-simulator-impl.cc b/src/core/model/default-simulator-impl.cc index 590fdc599..ba0609a65 100644 --- a/src/core/model/default-simulator-impl.cc +++ b/src/core/model/default-simulator-impl.cc @@ -69,7 +69,7 @@ DefaultSimulatorImpl::DefaultSimulatorImpl () // before ::Run is entered, the m_currentUid will be zero m_currentUid = 0; m_currentTs = 0; - m_currentContext = 0xffffffff; + m_currentContext = Simulator::NO_CONTEXT; m_unscheduledEvents = 0; m_eventsWithContextEmpty = true; m_main = SystemThread::Self(); diff --git a/src/core/model/realtime-simulator-impl.cc b/src/core/model/realtime-simulator-impl.cc index 4d9394390..b0baa8116 100644 --- a/src/core/model/realtime-simulator-impl.cc +++ b/src/core/model/realtime-simulator-impl.cc @@ -88,7 +88,7 @@ RealtimeSimulatorImpl::RealtimeSimulatorImpl () // before ::Run is entered, the m_currentUid will be zero m_currentUid = 0; m_currentTs = 0; - m_currentContext = 0xffffffff; + m_currentContext = Simulator::NO_CONTEXT; m_unscheduledEvents = 0; m_main = SystemThread::Self(); diff --git a/src/core/model/simulator.cc b/src/core/model/simulator.cc index a5dfbb3ba..d03c2d60c 100644 --- a/src/core/model/simulator.cc +++ b/src/core/model/simulator.cc @@ -96,7 +96,7 @@ TimePrinter (std::ostream &os) static void NodePrinter (std::ostream &os) { - if (Simulator::GetContext () == 0xffffffff) + if (Simulator::GetContext () == Simulator::NO_CONTEXT) { os << "-1"; } diff --git a/src/core/model/simulator.h b/src/core/model/simulator.h index 270b41fd5..fa94cdc72 100644 --- a/src/core/model/simulator.h +++ b/src/core/model/simulator.h @@ -64,8 +64,6 @@ class Scheduler; * A simple example of how to use the Simulator class to schedule events * is shown in sample-simulator.cc: * @include src/core/examples/sample-simulator.cc - * - * @todo Define what the simulation or event context means. */ class Simulator { @@ -168,6 +166,32 @@ public: */ static void Stop (const Time &delay); + /** + * Get the current simulation context. + * + * The simulation context is the ns-3 notion of a Logical Process. + * Events in a single context should only modify state associated with + * that context. Events for objects in other contexts should be + * scheduled with ScheduleWithContext() to track the context switches. + * In other words, events in different contexts should be mutually + * thread safe, by not modify overlapping model state. + * + * In circumstances where the context can't be determined, such as + * during object initialization, the \c enum value \c NO_CONTEXT + * should be used. + * + * @return The current simulation context + */ + static uint32_t GetContext (void); + + /** Context enum values. */ + enum { + /** + * Flag for events not associated with any particular context. + */ + NO_CONTEXT = 0xffffffff + }; + /** * @name Schedule events (in the same context) to run at a future time. */ @@ -1113,13 +1137,6 @@ public: */ static Time GetMaximumSimulationTime (void); - /** - * Get the current simulation context. - * - * @return The current simulation context - */ - static uint32_t GetContext (void); - /** * Schedule a future event execution (in the same context). * diff --git a/src/core/test/threaded-test-suite.cc b/src/core/test/threaded-test-suite.cc index b2b9d2069..e909e50ad 100644 --- a/src/core/test/threaded-test-suite.cc +++ b/src/core/test/threaded-test-suite.cc @@ -91,7 +91,7 @@ ThreadedSimulatorEventsTestCase::SchedulingThread (std::pairm_stop) { me->m_threadWaiting[threadno] = true; - Simulator::ScheduleWithContext (uint32_t (-1), + Simulator::ScheduleWithContext (threadno, MicroSeconds (1), &ThreadedSimulatorEventsTestCase::DoNothing, me, threadno); while (!me->m_stop && me->m_threadWaiting[threadno]) diff --git a/src/mpi/model/distributed-simulator-impl.cc b/src/mpi/model/distributed-simulator-impl.cc index f53849b20..f81f4d472 100644 --- a/src/mpi/model/distributed-simulator-impl.cc +++ b/src/mpi/model/distributed-simulator-impl.cc @@ -115,7 +115,7 @@ DistributedSimulatorImpl::DistributedSimulatorImpl () // before ::Run is entered, the m_currentUid will be zero m_currentUid = 0; m_currentTs = 0; - m_currentContext = 0xffffffff; + m_currentContext = Simulator::NO_CONTEXT; m_unscheduledEvents = 0; m_events = 0; } diff --git a/src/mpi/model/null-message-simulator-impl.cc b/src/mpi/model/null-message-simulator-impl.cc index ecec0a9f9..a9163c7ba 100644 --- a/src/mpi/model/null-message-simulator-impl.cc +++ b/src/mpi/model/null-message-simulator-impl.cc @@ -82,7 +82,7 @@ NullMessageSimulatorImpl::NullMessageSimulatorImpl () // before ::Run is entered, the m_currentUid will be zero m_currentUid = 0; m_currentTs = 0; - m_currentContext = 0xffffffff; + m_currentContext = Simulator::NO_CONTEXT; m_unscheduledEvents = 0; m_events = 0; diff --git a/src/visualizer/model/pyviz.cc b/src/visualizer/model/pyviz.cc index 4238786ba..82c19b07e 100644 --- a/src/visualizer/model/pyviz.cc +++ b/src/visualizer/model/pyviz.cc @@ -323,7 +323,7 @@ PyViz::SimulatorRunUntil (Time time) NS_LOG_LOGIC ("Schedule dummy callback to be called in " << (time - Simulator::Now ())); m_runUntil = time; m_stop = false; - Simulator::ScheduleWithContext (0xffffffff, time - Simulator::Now (), &PyViz::CallbackStopSimulation, this); + Simulator::ScheduleWithContext (Simulator::NO_CONTEXT, time - Simulator::Now (), &PyViz::CallbackStopSimulation, this); Ptr impl = Simulator::GetImplementation (); Ptr visualImpl = DynamicCast (impl);