Simulator,Scheduler和时间

章丰茂
2023-12-01

时间相关的成员定义

  • Scheduler::EventKey
uint64_t m_ts;// Event time stamp.

DefaultSimulatorImpl::ventWithContext

uint64_t timestamp;

时间相关函数

  • DefaultSimulatorImpl::DefaultSimulatorImpl
    m_currentTs = 0;
  • DefaultSimulatorImpl::ProcessOneEvent
    记schudler中下一个事件为next.
    m_currentTs = next.key.m_ts;
  • DefaultSimulatorImpl::ProcessEventsWithContext
    在eventsWithContext不空的时候,意义处理其中的每个事件。记每次取出的队首的事件为event.
Scheduler::Event ev;
ev.key.m_ts = m_currentTs + event.timestamp;//详见ScheduleWithContext函数的解释
  • DefaultSimulatorImpl::Stop
    在距现在间隔time的时候停止simulator
DefaultSimulatorImpl::Stop (Time const &time)
{
  NS_LOG_FUNCTION (this << time.GetTimeStep ());
  Simulator::Schedule (time, &Simulator::Stop);
}
  • DefaultSimulatorImpl::Schedule
EventId DefaultSimulatorImpl::Schedule (Time const &time, EventImpl *event)
{
  Time tAbsolute = time + TimeStep (m_currentTs);
  Scheduler::Event ev;
  ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep ();
}ScheduleWithContext
  • DefaultSimulatorImpl::ScheduleWithContext
    从程序上看,应该是只有主线程才能把事件插入到schduler中。如果是在主线程中schedule带context的事件,操作和不带context的事件一样。如果是在非主线程中schedule带context的事件,那么只把事件存于m_eventsWithContext。也就导致了日后将m_eventsWithContext中的事件添加到scheduler队列中时,事件的绝对时间戳=当前时间戳+ event.timestamp
void DefaultSimulatorImpl::ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event)
{
  if (SystemThread::Equals (m_main)){
  Time tAbsolute = time + TimeStep (m_currentTs);
  Scheduler::Event ev;
  ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep ();
  }
  else{
   EventWithContext ev;
   ev.timestamp = time.GetTimeStep ();
   创建临界区并把ev插入m_eventsWithContext中
  }
}
  • DefaultSimulatorImpl::ScheduleNow
EventId DefaultSimulatorImpl::ScheduleNow (EventImpl *event)
{
  ev.key.m_ts = m_currentTs;
 }
 类似资料: