A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
priority-queue-scheduler.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016 IITP
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Alexander Krotov <krotov@iitp.ru>
7
*/
8
9
#include "
priority-queue-scheduler.h
"
10
11
#include "
log.h
"
12
#include "
scheduler.h
"
13
14
#include <string>
15
16
/**
17
* @file
18
* @ingroup scheduler
19
* Implementation of ns3::PriorityQueueScheduler class.
20
*/
21
22
namespace
ns3
23
{
24
25
NS_LOG_COMPONENT_DEFINE
(
"PriorityQueueScheduler"
);
26
27
NS_OBJECT_ENSURE_REGISTERED
(
PriorityQueueScheduler
);
28
29
TypeId
30
PriorityQueueScheduler::GetTypeId
()
31
{
32
static
TypeId
tid =
TypeId
(
"ns3::PriorityQueueScheduler"
)
33
.
SetParent
<
Scheduler
>()
34
.SetGroupName(
"Core"
)
35
.AddConstructor<
PriorityQueueScheduler
>();
36
return
tid;
37
}
38
39
PriorityQueueScheduler::PriorityQueueScheduler
()
40
{
41
NS_LOG_FUNCTION
(
this
);
42
}
43
44
PriorityQueueScheduler::~PriorityQueueScheduler
()
45
{
46
NS_LOG_FUNCTION
(
this
);
47
}
48
49
void
50
PriorityQueueScheduler::Insert
(
const
Event
& ev)
51
{
52
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
53
m_queue
.push(ev);
54
}
55
56
bool
57
PriorityQueueScheduler::IsEmpty
()
const
58
{
59
NS_LOG_FUNCTION
(
this
);
60
return
m_queue
.empty();
61
}
62
63
Scheduler::Event
64
PriorityQueueScheduler::PeekNext
()
const
65
{
66
NS_LOG_FUNCTION
(
this
);
67
return
m_queue
.top();
68
}
69
70
Scheduler::Event
71
PriorityQueueScheduler::RemoveNext
()
72
{
73
NS_LOG_FUNCTION
(
this
);
74
Scheduler::Event
ev =
m_queue
.top();
75
m_queue
.pop();
76
return
ev;
77
}
78
79
bool
80
PriorityQueueScheduler::EventPriorityQueue::remove
(
const
Scheduler::Event
& ev)
81
{
82
auto
it = std::find(this->c.begin(), this->c.end(), ev);
83
if
(it != this->c.end())
84
{
85
this->c.erase(it);
86
std::make_heap(this->c.begin(), this->c.end(), this->comp);
87
return
true
;
88
}
89
else
90
{
91
return
false
;
92
}
93
}
94
95
void
96
PriorityQueueScheduler::Remove
(
const
Scheduler::Event
& ev)
97
{
98
NS_LOG_FUNCTION
(
this
);
99
m_queue
.remove(ev);
100
}
101
102
}
// namespace ns3
ns3::PriorityQueueScheduler::EventPriorityQueue::remove
bool remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
Definition
priority-queue-scheduler.cc:80
ns3::PriorityQueueScheduler
a std::priority_queue event scheduler
Definition
priority-queue-scheduler.h:55
ns3::PriorityQueueScheduler::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
priority-queue-scheduler.cc:30
ns3::PriorityQueueScheduler::RemoveNext
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Definition
priority-queue-scheduler.cc:71
ns3::PriorityQueueScheduler::~PriorityQueueScheduler
~PriorityQueueScheduler() override
Destructor.
Definition
priority-queue-scheduler.cc:44
ns3::PriorityQueueScheduler::Insert
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Definition
priority-queue-scheduler.cc:50
ns3::PriorityQueueScheduler::PeekNext
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
Definition
priority-queue-scheduler.cc:64
ns3::PriorityQueueScheduler::Remove
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
Definition
priority-queue-scheduler.cc:96
ns3::PriorityQueueScheduler::m_queue
EventPriorityQueue m_queue
The event queue.
Definition
priority-queue-scheduler.h:95
ns3::PriorityQueueScheduler::PriorityQueueScheduler
PriorityQueueScheduler()
Constructor.
Definition
priority-queue-scheduler.cc:39
ns3::PriorityQueueScheduler::IsEmpty
bool IsEmpty() const override
Test if the schedule is empty.
Definition
priority-queue-scheduler.cc:57
ns3::Scheduler
Maintain the event list.
Definition
scheduler.h:146
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:999
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:194
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:231
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
log.h
Debug message logging.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
priority-queue-scheduler.h
Declaration of ns3::PriorityQueueScheduler class.
scheduler.h
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::Scheduler::Event
Scheduler event.
Definition
scheduler.h:173
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition
scheduler.h:175
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition
scheduler.h:174
ns3::Scheduler::EventKey::m_ts
uint64_t m_ts
Event time stamp.
Definition
scheduler.h:160
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition
scheduler.h:161
src
core
model
priority-queue-scheduler.cc
Generated on
for ns-3 by
1.15.0