A Discrete-Event Network Simulator
API
calendar-scheduler.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef CALENDAR_SCHEDULER_H
22 #define CALENDAR_SCHEDULER_H
23 
24 #include "scheduler.h"
25 #include <stdint.h>
26 #include <list>
27 
34 namespace ns3 {
35 
36 class EventImpl;
37 
57 {
58 public:
63  static TypeId GetTypeId (void);
64 
68  virtual ~CalendarScheduler ();
69 
70  // Inherited
71  virtual void Insert (const Scheduler::Event &ev);
72  virtual bool IsEmpty (void) const;
73  virtual Scheduler::Event PeekNext (void) const;
74  virtual Scheduler::Event RemoveNext (void);
75  virtual void Remove (const Scheduler::Event &ev);
76 
77 private:
79  void ResizeUp (void);
81  void ResizeDown (void);
87  void Resize (uint32_t newSize);
93  uint32_t CalculateNewWidth (void);
101  void Init (uint32_t nBuckets,
102  uint64_t width,
103  uint64_t startPrio);
110  inline uint32_t Hash (uint64_t key) const;
112  void PrintInfo (void);
119  void DoResize (uint32_t newSize, uint32_t newWidth);
131  void DoInsert (const Scheduler::Event &ev);
132 
134  typedef std::list<Scheduler::Event> Bucket;
135 
137  Bucket *m_buckets;
139  uint32_t m_nBuckets;
141  uint64_t m_width;
143  uint32_t m_lastBucket;
145  uint64_t m_bucketTop;
147  uint64_t m_lastPrio;
149  uint32_t m_qSize;
150 };
151 
152 } // namespace ns3
153 
154 #endif /* CALENDAR_SCHEDULER_H */
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
void ResizeDown(void)
Halve the number of buckets if necessary.
uint32_t CalculateNewWidth(void)
Compute the new bucket size, based on up to the first 25 entries.
uint32_t m_qSize
Number of events in queue.
void DoInsert(const Scheduler::Event &ev)
Insert a new event in to the correct bucket.
void ResizeUp(void)
Double the number of buckets if necessary.
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
uint64_t m_bucketTop
Priority at the top of the bucket from which last event was dequeued.
virtual bool IsEmpty(void) const
Test if the schedule is empty.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
virtual ~CalendarScheduler()
Destructor.
void Init(uint32_t nBuckets, uint64_t width, uint64_t startPrio)
Initialize the calendar queue.
CalendarScheduler()
Constructor.
Maintain the event list.
Definition: scheduler.h:66
uint64_t m_width
Duration of a bucket, in dimensionless time units.
void Resize(uint32_t newSize)
Resize to a new number of buckets, with automatically computed width.
virtual Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
Bucket * m_buckets
Array of buckets.
Scheduler::Event DoRemoveNext(void)
Remove the earliest event.
Scheduler event.
Definition: scheduler.h:92
uint32_t m_lastBucket
Bucket index from which the last event was dequeued.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DoResize(uint32_t newSize, uint32_t newWidth)
Resize the number of buckets and width.
std::list< Scheduler::Event > Bucket
Calendar bucket type: a list of Events.
static TypeId GetTypeId(void)
Register this type.
a calendar queue event scheduler
uint64_t m_lastPrio
The priority of the last event removed.
uint32_t Hash(uint64_t key) const
Hash the dimensionless time to a bucket.
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_nBuckets
Number of buckets in the array.
void PrintInfo(void)
Print the configuration and bucket size distribution.