A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
priority-queue-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 IITP
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: Alexander Krotov <krotov@iitp.ru>
18 */
19
21
22#include "assert.h"
23#include "event-impl.h"
24#include "log-macros-disabled.h"
25#include "log.h"
26#include "scheduler.h"
27
28#include <string>
29
36namespace ns3
37{
38
39NS_LOG_COMPONENT_DEFINE("PriorityQueueScheduler");
40
41NS_OBJECT_ENSURE_REGISTERED(PriorityQueueScheduler);
42
43TypeId
45{
46 static TypeId tid = TypeId("ns3::PriorityQueueScheduler")
48 .SetGroupName("Core")
49 .AddConstructor<PriorityQueueScheduler>();
50 return tid;
51}
52
54{
55 NS_LOG_FUNCTION(this);
56}
57
59{
60 NS_LOG_FUNCTION(this);
61}
62
63void
65{
66 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
67 m_queue.push(ev);
68}
69
70bool
72{
73 NS_LOG_FUNCTION(this);
74 return m_queue.empty();
75}
76
79{
80 NS_LOG_FUNCTION(this);
81 return m_queue.top();
82}
83
86{
87 NS_LOG_FUNCTION(this);
88 Scheduler::Event ev = m_queue.top();
89 m_queue.pop();
90 return ev;
91}
92
93bool
95{
96 auto it = std::find(this->c.begin(), this->c.end(), ev);
97 if (it != this->c.end())
98 {
99 this->c.erase(it);
100 std::make_heap(this->c.begin(), this->c.end(), this->comp);
101 return true;
102 }
103 else
104 {
105 return false;
106 }
107}
108
109void
111{
112 NS_LOG_FUNCTION(this);
113 m_queue.remove(ev);
114}
115
116} // 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
static TypeId GetTypeId()
Register this type.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
~PriorityQueueScheduler() override
Destructor.
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
EventPriorityQueue m_queue
The event queue.
bool IsEmpty() const override
Test if the schedule is empty.
Maintain the event list.
Definition: scheduler.h:157
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
ns3::EventImpl declarations.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:46
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:184
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:186
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:185
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:171
uint32_t m_uid
Event unique id.
Definition: scheduler.h:172