A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
calendar-scheduler.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 * Author: Alexander Krotov <krotov@iitp.ru>
19 */
20
21#ifndef CALENDAR_SCHEDULER_H
22#define CALENDAR_SCHEDULER_H
23
24#include "scheduler.h"
25
26#include <list>
27#include <stdint.h>
28
35namespace ns3
36{
37
38class EventImpl;
39
94{
95 public:
100 static TypeId GetTypeId();
101
105 ~CalendarScheduler() override;
106
107 // Inherited
108 void Insert(const Scheduler::Event& ev) override;
109 bool IsEmpty() const override;
110 Scheduler::Event PeekNext() const override;
111 Scheduler::Event RemoveNext() override;
112 void Remove(const Scheduler::Event& ev) override;
113
114 private:
116 void ResizeUp();
118 void ResizeDown();
124 void Resize(uint32_t newSize);
130 uint64_t CalculateNewWidth();
138 void Init(uint32_t nBuckets, uint64_t width, uint64_t startPrio);
145 inline uint32_t Hash(uint64_t key) const;
147 void PrintInfo();
154 void DoResize(uint32_t newSize, uint64_t newWidth);
166 void DoInsert(const Scheduler::Event& ev);
167
169 typedef std::list<Scheduler::Event> Bucket;
170
176 uint64_t m_width;
180 uint64_t m_bucketTop;
182 uint64_t m_lastPrio;
185
195 void SetReverse(bool reverse);
201 Scheduler::Event& (*NextEvent)(Bucket& bucket);
208 bool (*Order)(const EventKey& newEvent, const EventKey& it);
213 void (*Pop)(Bucket&);
219 bool m_reverse = false;
220};
221
222} // namespace ns3
223
224#endif /* CALENDAR_SCHEDULER_H */
a calendar queue event scheduler
bool m_reverse
Bucket ordering.
uint64_t CalculateNewWidth()
Compute the new bucket size, based on up to the first 25 entries.
uint32_t m_nBuckets
Number of buckets in the array.
bool(* Order)(const EventKey &newEvent, const EventKey &it)
Ordering function to identify the insertion point, according to m_reverse.
void PrintInfo()
Print the configuration and bucket size distribution.
uint32_t m_qSize
Number of events in queue.
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
void Init(uint32_t nBuckets, uint64_t width, uint64_t startPrio)
Initialize the calendar queue.
void ResizeDown()
Halve the number of buckets if necessary.
uint32_t Hash(uint64_t key) const
Hash the dimensionless time to a bucket.
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
void DoInsert(const Scheduler::Event &ev)
Insert a new event in to the correct bucket.
uint64_t m_bucketTop
Priority at the top of the bucket from which last event was dequeued.
std::list< Scheduler::Event > Bucket
Calendar bucket type: a list of Events.
~CalendarScheduler() override
Destructor.
void DoResize(uint32_t newSize, uint64_t newWidth)
Resize the number of buckets and width.
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Scheduler::Event DoRemoveNext()
Remove the earliest event.
uint32_t m_lastBucket
Bucket index from which the last event was dequeued.
void SetReverse(bool reverse)
Set the insertion order.
void Resize(uint32_t newSize)
Resize to a new number of buckets, with automatically computed width.
bool IsEmpty() const override
Test if the schedule is empty.
uint64_t m_lastPrio
The priority of the last event removed.
uint64_t m_width
Duration of a bucket, in dimensionless time units.
void ResizeUp()
Double the number of buckets if necessary.
Bucket * m_buckets
Array of buckets.
void(* Pop)(Bucket &)
Pop the next event from the bucket, according to m_reverse.
static TypeId GetTypeId()
Register this type.
Maintain the event list.
Definition: scheduler.h:157
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
Scheduler event.
Definition: scheduler.h:184
Structure for sorting and comparing Events.
Definition: scheduler.h:170