A Discrete-Event Network Simulator
API
priority-queue-scheduler.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2016 IITP
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: Alexander Krotov <krotov@iitp.ru>
19 */
20
22#include "event-impl.h"
23#include "assert.h"
24#include "log-macros-disabled.h"
25#include "log.h"
26#include "scheduler.h"
27#include <string>
28
35namespace ns3 {
36
37NS_LOG_COMPONENT_DEFINE ("PriorityQueueScheduler");
38
39NS_OBJECT_ENSURE_REGISTERED (PriorityQueueScheduler);
40
41TypeId
43{
44 static TypeId tid = TypeId ("ns3::PriorityQueueScheduler")
46 .SetGroupName ("Core")
47 .AddConstructor<PriorityQueueScheduler> ()
48 ;
49 return tid;
50}
51
53{
54 NS_LOG_FUNCTION (this);
55}
57{
58 NS_LOG_FUNCTION (this);
59}
60
61void
63{
64 NS_LOG_FUNCTION (this << ev.impl << ev.key.m_ts << ev.key.m_uid);
65 m_queue.push (ev);
66}
67
68bool
70{
71 NS_LOG_FUNCTION (this);
72 return m_queue.empty ();
73}
74
77{
78 NS_LOG_FUNCTION (this);
79 return m_queue.top ();
80}
81
84{
85 NS_LOG_FUNCTION (this);
86 Scheduler::Event ev = m_queue.top ();
87 m_queue.pop ();
88 return ev;
89}
90
91bool
93{
94 auto it = std::find(this->c.begin(), this->c.end(), ev);
95 if (it != this->c.end())
96 {
97 this->c.erase(it);
98 std::make_heap(this->c.begin(), this->c.end(), this->comp);
99 return true;
100 }
101 else
102 {
103 return false;
104 }
105}
106
107void
109{
110 NS_LOG_FUNCTION (this);
111 m_queue.remove (ev);
112}
113
114} // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
bool remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
a std::priority_queue event scheduler
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
virtual bool IsEmpty(void) const
Test if the schedule is empty.
virtual ~PriorityQueueScheduler()
Destructor.
static TypeId GetTypeId(void)
Register this type.
EventPriorityQueue m_queue
The event queue.
virtual Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
Maintain the event list.
Definition: scheduler.h:156
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
ns3::EventImpl declarations.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Definition of empty logging macros and the NS_LOG_NOOP_INTERNAL macro.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of ns3::PriorityQueueScheduler class.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
Scheduler event.
Definition: scheduler.h:182
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:184
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:183
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:170
uint32_t m_uid
Event unique id.
Definition: scheduler.h:171