From 1d0c81dea4bb6bcf68c2e4776eefbecabc9b9ab3 Mon Sep 17 00:00:00 2001 From: Peter Barnes Date: Mon, 20 Dec 2021 21:59:44 +0000 Subject: [PATCH] core: pre-event hook, to facilitate chaining SimulatorImpls --- src/core/model/default-simulator-impl.cc | 8 ++++---- src/core/model/default-simulator-impl.h | 7 +++---- src/core/model/realtime-simulator-impl.cc | 4 ++++ src/core/model/simulator-impl.h | 7 +++++++ src/mpi/model/distributed-simulator-impl.cc | 3 +++ src/mpi/model/null-message-simulator-impl.cc | 3 +++ 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/core/model/default-simulator-impl.cc b/src/core/model/default-simulator-impl.cc index 2bb94d56a..c342c89e2 100644 --- a/src/core/model/default-simulator-impl.cc +++ b/src/core/model/default-simulator-impl.cc @@ -20,11 +20,8 @@ #include "simulator.h" #include "default-simulator-impl.h" -#include "scheduler.h" -#include "event-impl.h" -#include "ptr.h" -#include "pointer.h" +#include "scheduler.h" #include "assert.h" #include "log.h" @@ -135,6 +132,9 @@ DefaultSimulatorImpl::ProcessOneEvent (void) { Scheduler::Event next = m_events->RemoveNext (); + PreEventHook (EventId (next.impl, next.key.m_ts, + next.key.m_context, next.key.m_uid)); + NS_ASSERT (next.key.m_ts >= m_currentTs); m_unscheduledEvents--; m_eventCount++; diff --git a/src/core/model/default-simulator-impl.h b/src/core/model/default-simulator-impl.h index d05284e69..473dac89b 100644 --- a/src/core/model/default-simulator-impl.h +++ b/src/core/model/default-simulator-impl.h @@ -22,13 +22,9 @@ #define DEFAULT_SIMULATOR_IMPL_H #include "simulator-impl.h" -#include "scheduler.h" -#include "event-impl.h" #include "system-thread.h" #include "system-mutex.h" -#include "ptr.h" - #include /** @@ -39,6 +35,9 @@ namespace ns3 { +// Forward +class Scheduler; + /** * \ingroup simulator * diff --git a/src/core/model/realtime-simulator-impl.cc b/src/core/model/realtime-simulator-impl.cc index ab0f76912..e4bb08703 100644 --- a/src/core/model/realtime-simulator-impl.cc +++ b/src/core/model/realtime-simulator-impl.cc @@ -325,6 +325,10 @@ RealtimeSimulatorImpl::ProcessOneEvent (void) NS_ASSERT_MSG (m_events->IsEmpty () == false, "RealtimeSimulatorImpl::ProcessOneEvent(): event queue is empty"); next = m_events->RemoveNext (); + + PreEventHook (EventId (next.impl, next.key.m_ts, + next.key.m_context, next.key.m_uid)); + m_unscheduledEvents--; m_eventCount++; diff --git a/src/core/model/simulator-impl.h b/src/core/model/simulator-impl.h index afde956bc..50f76a721 100644 --- a/src/core/model/simulator-impl.h +++ b/src/core/model/simulator-impl.h @@ -102,6 +102,13 @@ public: /** \copydoc Simulator::GetEventCount */ virtual uint64_t GetEventCount (void) const = 0; + /** + * Hook called before processing each event. + * + * \param [in] id The event about to be processed. + */ + virtual void PreEventHook (const EventId & id) {}; + }; } // namespace ns3 diff --git a/src/mpi/model/distributed-simulator-impl.cc b/src/mpi/model/distributed-simulator-impl.cc index 91cda1957..b59700a87 100644 --- a/src/mpi/model/distributed-simulator-impl.cc +++ b/src/mpi/model/distributed-simulator-impl.cc @@ -309,6 +309,9 @@ DistributedSimulatorImpl::ProcessOneEvent (void) Scheduler::Event next = m_events->RemoveNext (); + PreEventHook (EventId (next.impl, next.key.m_ts, + next.key.m_context, next.key.m_uid)); + NS_ASSERT (next.key.m_ts >= m_currentTs); m_unscheduledEvents--; m_eventCount++; diff --git a/src/mpi/model/null-message-simulator-impl.cc b/src/mpi/model/null-message-simulator-impl.cc index 0d77baa5f..c4d2b1ab7 100644 --- a/src/mpi/model/null-message-simulator-impl.cc +++ b/src/mpi/model/null-message-simulator-impl.cc @@ -230,6 +230,9 @@ NullMessageSimulatorImpl::ProcessOneEvent (void) Scheduler::Event next = m_events->RemoveNext (); + PreEventHook (EventId (next.impl, next.key.m_ts, + next.key.m_context, next.key.m_uid)); + NS_ASSERT (next.key.m_ts >= m_currentTs); m_unscheduledEvents--; m_eventCount++;