View | Details | Raw Unified | Return to bug 230
Collapse All | Expand All

(-)a/src/simulator/default-simulator-impl.cc (-10 / +1 lines)
 Lines 49-55    Link Here 
49
DefaultSimulatorImpl::DefaultSimulatorImpl ()
49
DefaultSimulatorImpl::DefaultSimulatorImpl ()
50
{
50
{
51
  m_stop = false;
51
  m_stop = false;
52
  m_stopAt = 0;
53
  // uids are allocated from 4.
52
  // uids are allocated from 4.
54
  // uid 0 is "invalid" events
53
  // uid 0 is "invalid" events
55
  // uid 1 is "now" events
54
  // uid 1 is "now" events
 Lines 146-153    Link Here 
146
DefaultSimulatorImpl::Run (void)
145
DefaultSimulatorImpl::Run (void)
147
{
146
{
148
147
149
  while (!m_events->IsEmpty () && !m_stop && 
148
  while (!m_events->IsEmpty () && !m_stop) 
150
         (m_stopAt == 0 || m_stopAt > NextTs ())) 
151
    {
149
    {
152
      ProcessOneEvent ();
150
      ProcessOneEvent ();
153
    }
151
    }
 Lines 169-181    Link Here 
169
  m_stop = true;
167
  m_stop = true;
170
}
168
}
171
169
172
void 
173
DefaultSimulatorImpl::Stop (Time const &time)
174
{
175
  NS_ASSERT (time.IsPositive ());
176
  Time absolute = Simulator::Now () + time;
177
  m_stopAt = absolute.GetTimeStep ();
178
}
179
170
180
//
171
//
181
// Schedule an event for a _relative_ time in the future.
172
// Schedule an event for a _relative_ time in the future.
(-)a/src/simulator/default-simulator-impl.h (-2 lines)
 Lines 45-51    Link Here 
45
  virtual bool IsFinished (void) const;
45
  virtual bool IsFinished (void) const;
46
  virtual Time Next (void) const;
46
  virtual Time Next (void) const;
47
  virtual void Stop (void);
47
  virtual void Stop (void);
48
  virtual void Stop (Time const &time);
49
  virtual EventId Schedule (Time const &time, EventImpl *event);
48
  virtual EventId Schedule (Time const &time, EventImpl *event);
50
  virtual EventId ScheduleNow (EventImpl *event);
49
  virtual EventId ScheduleNow (EventImpl *event);
51
  virtual EventId ScheduleDestroy (EventImpl *event);
50
  virtual EventId ScheduleDestroy (EventImpl *event);
 Lines 66-72    Link Here 
66
65
67
  typedef std::list<EventId> DestroyEvents;
66
  typedef std::list<EventId> DestroyEvents;
68
  DestroyEvents m_destroyEvents;
67
  DestroyEvents m_destroyEvents;
69
  uint64_t m_stopAt;
70
  bool m_stop;
68
  bool m_stop;
71
  Ptr<Scheduler> m_events;
69
  Ptr<Scheduler> m_events;
72
  uint32_t m_uid;
70
  uint32_t m_uid;
(-)a/src/simulator/realtime-simulator-impl.cc (-42 lines)
 Lines 68-74    Link Here 
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
 Lines 441-456    Link Here 
441
          {
440
          {
442
            done = true;
441
            done = true;
443
          }
442
          }
444
        //
445
        // We also want to stop the simulator at some time even if there are events 
446
        // that have been scheduled out in the future.  If we're in realtime mode, we 
447
        // actually have time passing, so we must look at the realtime clock to see if 
448
        // we're past the end time.
449
        //
450
        if (m_stopAt && m_stopAt <= m_synchronizer->GetCurrentRealtime ())
451
          {
452
            done = true;
453
          }
454
      }
443
      }
455
444
456
      if (done)
445
      if (done)
 Lines 537-573    Link Here 
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
//
(-)a/src/simulator/realtime-simulator-impl.h (-2 lines)
 Lines 55-61    Link Here 
55
  virtual bool IsFinished (void) const;
55
  virtual bool IsFinished (void) const;
56
  virtual Time Next (void) const;
56
  virtual Time Next (void) const;
57
  virtual void Stop (void);
57
  virtual void Stop (void);
58
  virtual void Stop (Time const &time);
59
  virtual EventId Schedule (Time const &time, EventImpl *event);
58
  virtual EventId Schedule (Time const &time, EventImpl *event);
60
  virtual EventId ScheduleNow (EventImpl *event);
59
  virtual EventId ScheduleNow (EventImpl *event);
61
  virtual EventId ScheduleDestroy (EventImpl *event);
60
  virtual EventId ScheduleDestroy (EventImpl *event);
 Lines 89-95    Link Here 
89
88
90
  typedef std::list<EventId> DestroyEvents;
89
  typedef std::list<EventId> DestroyEvents;
91
  DestroyEvents m_destroyEvents;
90
  DestroyEvents m_destroyEvents;
92
  uint64_t m_stopAt;
93
  bool m_stop;
91
  bool m_stop;
94
  bool m_running;
92
  bool m_running;
95
93
(-)a/src/simulator/simulator-impl.h (-1 lines)
 Lines 38-44    Link Here 
38
  virtual bool IsFinished (void) const = 0;
38
  virtual bool IsFinished (void) const = 0;
39
  virtual Time Next (void) const = 0;
39
  virtual Time Next (void) const = 0;
40
  virtual void Stop (void) = 0;
40
  virtual void Stop (void) = 0;
41
  virtual void Stop (Time const &time) = 0;
42
  virtual EventId Schedule (Time const &time, EventImpl *event) = 0;
41
  virtual EventId Schedule (Time const &time, EventImpl *event) = 0;
43
  virtual EventId ScheduleNow (EventImpl *event) = 0;
42
  virtual EventId ScheduleNow (EventImpl *event) = 0;
44
  virtual EventId ScheduleDestroy (EventImpl *event) = 0;
43
  virtual EventId ScheduleDestroy (EventImpl *event) = 0;
(-)a/src/simulator/simulator.cc (-1 / +1 lines)
 Lines 169-175    Link Here 
169
Simulator::Stop (Time const &time)
169
Simulator::Stop (Time const &time)
170
{
170
{
171
  NS_LOG_FUNCTION (time);
171
  NS_LOG_FUNCTION (time);
172
  GetImpl ()->Stop (time);
172
  Simulator::Schedule (time, &Simulator::Stop);
173
}
173
}
174
174
175
Time
175
Time

Return to bug 230