66 RealtimeSimulatorImpl::RealtimeSimulatorImpl () |
66 RealtimeSimulatorImpl::RealtimeSimulatorImpl () |
67 { |
67 { |
68 NS_LOG_FUNCTION_NOARGS (); |
68 NS_LOG_FUNCTION_NOARGS (); |
69 |
69 |
70 m_stop = false; |
70 m_stop = false; |
71 m_stopAt = 0; |
|
72 m_running = false; |
71 m_running = false; |
73 // uids are allocated from 4. |
72 // uids are allocated from 4. |
74 // uid 0 is "invalid" events |
73 // uid 0 is "invalid" events |
75 // uid 1 is "now" events |
74 // uid 1 is "now" events |
76 // uid 2 is "destroy" events |
75 // uid 2 is "destroy" events |
535 void |
524 void |
536 RealtimeSimulatorImpl::Stop (void) |
525 RealtimeSimulatorImpl::Stop (void) |
537 { |
526 { |
538 NS_LOG_FUNCTION_NOARGS (); |
527 NS_LOG_FUNCTION_NOARGS (); |
539 m_stop = true; |
528 m_stop = true; |
540 } |
|
541 |
|
542 static void Placeholder (void) {} |
|
543 |
|
544 // |
|
545 // Schedule a stop for a _relative_ time in the future. If the simulation |
|
546 // hasn't started yet, this will effectively be an absolute time. |
|
547 // |
|
548 void |
|
549 RealtimeSimulatorImpl::Stop (Time const &time) |
|
550 { |
|
551 NS_LOG_FUNCTION (time); |
|
552 |
|
553 Time tAbsolute = Simulator::Now () + time; |
|
554 NS_ASSERT (tAbsolute.IsPositive ()); |
|
555 NS_ASSERT (tAbsolute >= TimeStep (m_currentTs)); |
|
556 m_stopAt = tAbsolute.GetTimeStep (); |
|
557 |
|
558 // |
|
559 // For the realtime case, we need a real event sitting out at the end of time |
|
560 // to keep the simulator running (sleeping) while there are no other events |
|
561 // present. If an "external" device in another thread decides to schedule an |
|
562 // event, the sleeping synchronizer will be awakened and the new event will |
|
563 // be run. |
|
564 // |
|
565 // The easiest thing to do is to call back up into the simulator to take |
|
566 // advantage of all of the nice event wrappers. This will call back down into |
|
567 // RealtimeSimulatorImpl::Schedule to do the work. This path interprets the |
|
568 // time as relative, so pass the relative time. |
|
569 // |
|
570 Simulator::Schedule (time, &Placeholder); |
|
571 } |
529 } |
572 |
530 |
573 // |
531 // |
574 // Schedule an event for a _relative_ time in the future. |
532 // Schedule an event for a _relative_ time in the future. |
575 // |
533 // |