src/simulator/realtime-simulator-impl.cc
changeset 3809 5e007004402e
parent 3808 ace932ee6eef
child 3811 4eb8e926c6d7
equal deleted inserted replaced
3808:ace932ee6eef 3809:5e007004402e
   644 }
   644 }
   645 
   645 
   646 //
   646 //
   647 // Schedule an event for a _relative_ time in the future.
   647 // Schedule an event for a _relative_ time in the future.
   648 //
   648 //
   649 EventId
   649 void
   650 RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, const Ptr<EventImpl> &impl)
   650 RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, EventImpl *impl)
   651 {
   651 {
   652   NS_LOG_FUNCTION (time << impl);
   652   NS_LOG_FUNCTION (time << impl);
   653 
   653 
   654   Scheduler::Event ev;
   654   
   655   {
   655   {
   656     CriticalSection cs (m_mutex);
   656     CriticalSection cs (m_mutex);
   657 
   657 
   658     uint64_t ts = m_synchronizer->GetCurrentRealtime () + time.GetTimeStep ();
   658     uint64_t ts = m_synchronizer->GetCurrentRealtime () + time.GetTimeStep ();
   659     NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
   659     NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
   660     ev.impl = GetPointer (impl);
   660     Scheduler::Event ev;
       
   661     ev.impl = impl;
   661     ev.key.m_ts = ts;
   662     ev.key.m_ts = ts;
   662     ev.key.m_uid = m_uid;
   663     ev.key.m_uid = m_uid;
   663     m_uid++;
   664     m_uid++;
   664     ++m_unscheduledEvents;
   665     ++m_unscheduledEvents;
   665     m_events->Insert (ev);
   666     m_events->Insert (ev);
   666     m_synchronizer->Signal ();
   667     m_synchronizer->Signal ();
   667   }
   668   }
   668 
   669 
   669   return EventId (impl, ev.key.m_ts, ev.key.m_uid);
   670 }
   670 }
   671 
   671 
   672 void
   672 EventId
   673 RealtimeSimulatorImpl::ScheduleRealtimeNow (EventImpl *impl)
   673 RealtimeSimulatorImpl::ScheduleRealtimeNow (const Ptr<EventImpl> &impl)
   674 {
   674 {
   675   NS_LOG_FUNCTION_NOARGS ();
   675   NS_LOG_FUNCTION_NOARGS ();
       
   676   Scheduler::Event ev;
       
   677   {
   676   {
   678     CriticalSection cs (m_mutex);
   677     CriticalSection cs (m_mutex);
   679 
   678 
   680     //
   679     //
   681     // If the simulator is running, we're pacing and have a meaningful 
   680     // If the simulator is running, we're pacing and have a meaningful 
   682     // realtime clock.  If we're not, then m_currentTs is were we stopped.
   681     // realtime clock.  If we're not, then m_currentTs is were we stopped.
   683     // 
   682     // 
   684     uint64_t ts = m_running ? m_synchronizer->GetCurrentRealtime () : m_currentTs;
   683     uint64_t ts = m_running ? m_synchronizer->GetCurrentRealtime () : m_currentTs;
   685     NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealrimeNow(): schedule for time < m_currentTs");
   684     NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealrimeNow(): schedule for time < m_currentTs");
   686     ev.impl = GetPointer (impl);
   685     Scheduler::Event ev;
       
   686     ev.impl = impl;
   687     ev.key.m_ts = ts;
   687     ev.key.m_ts = ts;
   688     ev.key.m_uid = m_uid;
   688     ev.key.m_uid = m_uid;
   689     m_uid++;
   689     m_uid++;
   690     ++m_unscheduledEvents;
   690     ++m_unscheduledEvents;
   691     m_events->Insert (ev);
   691     m_events->Insert (ev);
   692     m_synchronizer->Signal ();
   692     m_synchronizer->Signal ();
   693   }
   693   }
   694 
       
   695   return EventId (impl, ev.key.m_ts, ev.key.m_uid);
       
   696 }
   694 }
   697 
   695 
   698 Time
   696 Time
   699 RealtimeSimulatorImpl::RealtimeNow (void) const
   697 RealtimeSimulatorImpl::RealtimeNow (void) const
   700 {
   698 {