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 * Author: Alexander Krotov <krotov@iitp.ru>
20 */
21
22#ifndef CALENDAR_SCHEDULER_H
23#define CALENDAR_SCHEDULER_H
24
25#include "scheduler.h"
26#include <stdint.h>
27#include <list>
28
35namespace ns3 {
36
37class EventImpl;
38
93{
94public:
99 static TypeId GetTypeId (void);
100
104 virtual ~CalendarScheduler ();
105
106 // Inherited
107 virtual void Insert (const Scheduler::Event &ev);
108 virtual bool IsEmpty (void) const;
109 virtual Scheduler::Event PeekNext (void) const;
110 virtual Scheduler::Event RemoveNext (void);
111 virtual void Remove (const Scheduler::Event &ev);
112
113private:
115 void ResizeUp (void);
117 void ResizeDown (void);
123 void Resize (uint32_t newSize);
129 uint64_t CalculateNewWidth (void);
137 void Init (uint32_t nBuckets,
138 uint64_t width,
139 uint64_t startPrio);
146 inline uint32_t Hash (uint64_t key) const;
148 void PrintInfo (void);
155 void DoResize (uint32_t newSize, uint64_t newWidth);
167 void DoInsert (const Scheduler::Event &ev);
168
170 typedef std::list<Scheduler::Event> Bucket;
171
177 uint64_t m_width;
181 uint64_t m_bucketTop;
183 uint64_t m_lastPrio;
186
196 void SetReverse (bool reverse);
202 Scheduler::Event & (*NextEvent) (Bucket & bucket);
209 bool (*Order) (const EventKey & newEvent, const EventKey & it);
214 void (*Pop) (Bucket &);
220 bool m_reverse = false;
221};
222
223} // namespace ns3
224
225#endif /* CALENDAR_SCHEDULER_H */
a calendar queue event scheduler
bool m_reverse
Bucket ordering.
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.
uint32_t m_qSize
Number of events in queue.
uint64_t CalculateNewWidth(void)
Compute the new bucket size, based on up to the first 25 entries.
virtual bool IsEmpty(void) const
Test if the schedule is empty.
void Init(uint32_t nBuckets, uint64_t width, uint64_t startPrio)
Initialize the calendar queue.
Scheduler::Event DoRemoveNext(void)
Remove the earliest event.
uint32_t Hash(uint64_t key) const
Hash the dimensionless time to a bucket.
void ResizeUp(void)
Double the number of buckets if necessary.
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
static TypeId GetTypeId(void)
Register this type.
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.
void DoResize(uint32_t newSize, uint64_t newWidth)
Resize the number of buckets and width.
uint32_t m_lastBucket
Bucket index from which the last event was dequeued.
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
void SetReverse(bool reverse)
Set the insertion order.
virtual ~CalendarScheduler()
Destructor.
void Resize(uint32_t newSize)
Resize to a new number of buckets, with automatically computed width.
uint64_t m_lastPrio
The priority of the last event removed.
uint64_t m_width
Duration of a bucket, in dimensionless time units.
Bucket * m_buckets
Array of buckets.
void ResizeDown(void)
Halve the number of buckets if necessary.
virtual Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
void(* Pop)(Bucket &)
Pop the next event from the bucket, according to m_reverse.
void PrintInfo(void)
Print the configuration and bucket size distribution.
Maintain the event list.
Definition: scheduler.h:156
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:182
Structure for sorting and comparing Events.
Definition: scheduler.h:169