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:
Alexander Krotov
2019-04-03 20:03:42 +03:00
parent 9cd441a0b0
commit 1f1f10e13a

View File

@@ -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);
}
}
/*