energy: reschedule UpdateEnergySource only if it has already expired
Otherwise, if energy consumption is queried frequently, canceled events are produced. These events take up memory and slow down the simulator.
This commit is contained in:
@@ -154,8 +154,6 @@ BasicEnergySource::UpdateEnergySource (void)
|
||||
NS_LOG_FUNCTION (this);
|
||||
NS_LOG_DEBUG ("BasicEnergySource:Updating remaining energy.");
|
||||
|
||||
m_energyUpdateEvent.Cancel ();
|
||||
|
||||
double remainingEnergy = m_remainingEnergyJ;
|
||||
CalculateRemainingEnergy ();
|
||||
|
||||
@@ -176,9 +174,12 @@ BasicEnergySource::UpdateEnergySource (void)
|
||||
NotifyEnergyChanged ();
|
||||
}
|
||||
|
||||
m_energyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval,
|
||||
&BasicEnergySource::UpdateEnergySource,
|
||||
this);
|
||||
if (m_energyUpdateEvent.IsExpired ())
|
||||
{
|
||||
m_energyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval,
|
||||
&BasicEnergySource::UpdateEnergySource,
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user