Add logging to default-simulator-impl.cc and fix some outdated documentation.

This commit is contained in:
Vedran Miletić
2012-10-06 21:36:39 +02:00
parent 5cb935ed4f
commit dd61b3dced
2 changed files with 30 additions and 13 deletions

View File

@@ -48,6 +48,7 @@ DefaultSimulatorImpl::GetTypeId (void)
DefaultSimulatorImpl::DefaultSimulatorImpl ()
{
NS_LOG_FUNCTION_NOARGS ();
m_stop = false;
// uids are allocated from 4.
// uid 0 is "invalid" events
@@ -65,11 +66,13 @@ DefaultSimulatorImpl::DefaultSimulatorImpl ()
DefaultSimulatorImpl::~DefaultSimulatorImpl ()
{
NS_LOG_FUNCTION_NOARGS ();
}
void
DefaultSimulatorImpl::DoDispose (void)
{
NS_LOG_FUNCTION_NOARGS ();
while (!m_events->IsEmpty ())
{
Scheduler::Event next = m_events->RemoveNext ();
@@ -81,6 +84,7 @@ DefaultSimulatorImpl::DoDispose (void)
void
DefaultSimulatorImpl::Destroy ()
{
NS_LOG_FUNCTION_NOARGS ();
while (!m_destroyEvents.empty ())
{
Ptr<EventImpl> ev = m_destroyEvents.front ().PeekEventImpl ();
@@ -96,6 +100,7 @@ DefaultSimulatorImpl::Destroy ()
void
DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
NS_LOG_FUNCTION (this << &schedulerFactory);
Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
if (m_events != 0)
@@ -113,12 +118,14 @@ DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
uint32_t
DefaultSimulatorImpl::GetSystemId (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return 0;
}
void
DefaultSimulatorImpl::ProcessOneEvent (void)
{
NS_LOG_FUNCTION_NOARGS ();
Scheduler::Event next = m_events->RemoveNext ();
NS_ASSERT (next.key.m_ts >= m_currentTs);
@@ -137,12 +144,14 @@ DefaultSimulatorImpl::ProcessOneEvent (void)
bool
DefaultSimulatorImpl::IsFinished (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_events->IsEmpty () || m_stop;
}
void
DefaultSimulatorImpl::ProcessEventsWithContext (void)
{
NS_LOG_FUNCTION_NOARGS ();
if (m_eventsWithContextEmpty)
{
return;
@@ -173,6 +182,7 @@ DefaultSimulatorImpl::ProcessEventsWithContext (void)
void
DefaultSimulatorImpl::Run (void)
{
NS_LOG_FUNCTION_NOARGS ();
// Set the current threadId as the main threadId
m_main = SystemThread::Self();
ProcessEventsWithContext ();
@@ -191,12 +201,14 @@ DefaultSimulatorImpl::Run (void)
void
DefaultSimulatorImpl::Stop (void)
{
NS_LOG_FUNCTION_NOARGS ();
m_stop = true;
}
void
DefaultSimulatorImpl::Stop (Time const &time)
{
NS_LOG_FUNCTION (this << time.GetTimeStep ());
Simulator::Schedule (time, &Simulator::Stop);
}
@@ -206,6 +218,7 @@ DefaultSimulatorImpl::Stop (Time const &time)
EventId
DefaultSimulatorImpl::Schedule (Time const &time, EventImpl *event)
{
NS_LOG_FUNCTION (this << time.GetTimeStep () << event);
NS_ASSERT_MSG (SystemThread::Equals (m_main), "Simulator::Schedule Thread-unsafe invocation!");
Time tAbsolute = time + TimeStep (m_currentTs);
@@ -257,6 +270,7 @@ DefaultSimulatorImpl::ScheduleWithContext (uint32_t context, Time const &time, E
EventId
DefaultSimulatorImpl::ScheduleNow (EventImpl *event)
{
NS_LOG_FUNCTION (this << event);
NS_ASSERT_MSG (SystemThread::Equals (m_main), "Simulator::ScheduleNow Thread-unsafe invocation!");
Scheduler::Event ev;
@@ -273,6 +287,7 @@ DefaultSimulatorImpl::ScheduleNow (EventImpl *event)
EventId
DefaultSimulatorImpl::ScheduleDestroy (EventImpl *event)
{
NS_LOG_FUNCTION (this << event);
NS_ASSERT_MSG (SystemThread::Equals (m_main), "Simulator::ScheduleDestroy Thread-unsafe invocation!");
EventId id (Ptr<EventImpl> (event, false), m_currentTs, 0xffffffff, 2);
@@ -284,12 +299,14 @@ DefaultSimulatorImpl::ScheduleDestroy (EventImpl *event)
Time
DefaultSimulatorImpl::Now (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return TimeStep (m_currentTs);
}
Time
DefaultSimulatorImpl::GetDelayLeft (const EventId &id) const
{
NS_LOG_FUNCTION (this << id.GetTs () << id.GetContext () << id.GetUid ());
if (IsExpired (id))
{
return TimeStep (0);
@@ -303,6 +320,7 @@ DefaultSimulatorImpl::GetDelayLeft (const EventId &id) const
void
DefaultSimulatorImpl::Remove (const EventId &id)
{
NS_LOG_FUNCTION (this << id.GetTs () << id.GetContext () << id.GetUid ());
if (id.GetUid () == 2)
{
// destroy events.
@@ -336,6 +354,7 @@ DefaultSimulatorImpl::Remove (const EventId &id)
void
DefaultSimulatorImpl::Cancel (const EventId &id)
{
NS_LOG_FUNCTION (this << id.GetTs () << id.GetContext () << id.GetUid ());
if (!IsExpired (id))
{
id.PeekEventImpl ()->Cancel ();
@@ -345,6 +364,7 @@ DefaultSimulatorImpl::Cancel (const EventId &id)
bool
DefaultSimulatorImpl::IsExpired (const EventId &ev) const
{
NS_LOG_FUNCTION (this << ev.GetTs () << ev.GetContext () << ev.GetUid ());
if (ev.GetUid () == 2)
{
if (ev.PeekEventImpl () == 0 ||
@@ -379,6 +399,7 @@ DefaultSimulatorImpl::IsExpired (const EventId &ev) const
Time
DefaultSimulatorImpl::GetMaximumSimulationTime (void) const
{
NS_LOG_FUNCTION_NOARGS ();
// XXX: I am fairly certain other compilers use other non-standard
// post-fixes to indicate 64 bit constants.
return TimeStep (0x7fffffffffffffffLL);
@@ -387,9 +408,8 @@ DefaultSimulatorImpl::GetMaximumSimulationTime (void) const
uint32_t
DefaultSimulatorImpl::GetContext (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_currentContext;
}
} // namespace ns3

View File

@@ -38,14 +38,11 @@ public:
static TypeId GetTypeId (void);
/**
* Every event scheduled by the Simulator::insertAtDestroy method is
* invoked. Then, we ensure that any memory allocated by the
* Simulator is freed.
* This method is typically invoked at the end of a simulation
* to avoid false-positive reports by a leak checker.
* After this method has been invoked, it is actually possible
* to restart a new simulation with a set of calls to Simulator::run
* and Simulator::insert_*.
* to restart a new simulation with a set of calls to Simulator::Run,
* Simulator::Schedule and Simulator::ScheduleWithContext.
*/
virtual void Destroy () = 0;
/**
@@ -56,12 +53,12 @@ public:
virtual bool IsFinished (void) const = 0;
/**
* If an event invokes this method, it will be the last
* event scheduled by the Simulator::run method before
* event scheduled by the Simulator::Run method before
* returning to the caller.
*/
virtual void Stop (void) = 0;
/**
* Force the Simulator::run method to return to the caller when the
* Force the Simulator::Run method to return to the caller when the
* expiration time of the next event to be processed is greater than
* or equal to the stop time. The stop time is relative to the
* current simulation time.
@@ -119,9 +116,9 @@ public:
* Set the cancel bit on this event: the event's associated function
* will not be invoked when it expires.
* This method has the same visible effect as the
* ns3::Simulator::remove method but its algorithmic complexity is
* ns3::Simulator::Remove method but its algorithmic complexity is
* much lower: it has O(1) complexity.
* This method has the exact same semantics as ns3::EventId::cancel.
* This method has the exact same semantics as ns3::EventId::Cancel.
* Note that it is not possible to cancel events which were scheduled
* for the "destroy" time. Doing so will result in a program error (crash).
*
@@ -144,8 +141,8 @@ public:
/**
* Run the simulation until one of:
* - no events are present anymore
* - the user called Simulator::stop
* - the user called Simulator::stopAtUs and the
* - the user called Simulator::Stop
* - the user called Simulator::Stop with stop time and the
* expiration time of the next event to be processed
* is greater than or equal to the stop time.
*/