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 "
assert.h
"
12
#include "
event-impl.h
"
13
#include "
log-macros-disabled.h
"
14
#include "
log.h
"
15
#include "
scheduler.h
"
16
17
#include <string>
18
19
/**
20
* \file
21
* \ingroup scheduler
22
* Implementation of ns3::PriorityQueueScheduler class.
23
*/
24
25
namespace
ns3
26
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"PriorityQueueScheduler"
);
29
30
NS_OBJECT_ENSURE_REGISTERED
(PriorityQueueScheduler);
31
32
TypeId
33
PriorityQueueScheduler::GetTypeId
()
34
{
35
static
TypeId
tid =
TypeId
(
"ns3::PriorityQueueScheduler"
)
36
.
SetParent
<
Scheduler
>()
37
.SetGroupName(
"Core"
)
38
.AddConstructor<
PriorityQueueScheduler
>();
39
return
tid;
40
}
41
42
PriorityQueueScheduler::PriorityQueueScheduler
()
43
{
44
NS_LOG_FUNCTION
(
this
);
45
}
46
47
PriorityQueueScheduler::~PriorityQueueScheduler
()
48
{
49
NS_LOG_FUNCTION
(
this
);
50
}
51
52
void
53
PriorityQueueScheduler::Insert
(
const
Event
& ev)
54
{
55
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
56
m_queue
.push(ev);
57
}
58
59
bool
60
PriorityQueueScheduler::IsEmpty
()
const
61
{
62
NS_LOG_FUNCTION
(
this
);
63
return
m_queue
.empty();
64
}
65
66
Scheduler::Event
67
PriorityQueueScheduler::PeekNext
()
const
68
{
69
NS_LOG_FUNCTION
(
this
);
70
return
m_queue
.top();
71
}
72
73
Scheduler::Event
74
PriorityQueueScheduler::RemoveNext
()
75
{
76
NS_LOG_FUNCTION
(
this
);
77
Scheduler::Event
ev =
m_queue
.top();
78
m_queue
.pop();
79
return
ev;
80
}
81
82
bool
83
PriorityQueueScheduler::EventPriorityQueue::remove
(
const
Scheduler::Event
& ev)
84
{
85
auto
it = std::find(this->c.begin(), this->c.end(), ev);
86
if
(it != this->c.end())
87
{
88
this->c.erase(it);
89
std::make_heap(this->c.begin(), this->c.end(), this->comp);
90
return
true
;
91
}
92
else
93
{
94
return
false
;
95
}
96
}
97
98
void
99
PriorityQueueScheduler::Remove
(
const
Scheduler::Event
& ev)
100
{
101
NS_LOG_FUNCTION
(
this
);
102
m_queue
.
remove
(ev);
103
}
104
105
}
// namespace ns3
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::PriorityQueueScheduler::EventPriorityQueue::remove
bool remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
Definition
priority-queue-scheduler.cc:83
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:33
ns3::PriorityQueueScheduler::RemoveNext
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Definition
priority-queue-scheduler.cc:74
ns3::PriorityQueueScheduler::~PriorityQueueScheduler
~PriorityQueueScheduler() override
Destructor.
Definition
priority-queue-scheduler.cc:47
ns3::PriorityQueueScheduler::Insert
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Definition
priority-queue-scheduler.cc:53
ns3::PriorityQueueScheduler::PeekNext
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
Definition
priority-queue-scheduler.cc:67
ns3::PriorityQueueScheduler::Remove
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
Definition
priority-queue-scheduler.cc:99
ns3::PriorityQueueScheduler::m_queue
EventPriorityQueue m_queue
The event queue.
Definition
priority-queue-scheduler.h:94
ns3::PriorityQueueScheduler::PriorityQueueScheduler
PriorityQueueScheduler()
Constructor.
Definition
priority-queue-scheduler.cc:42
ns3::PriorityQueueScheduler::IsEmpty
bool IsEmpty() const override
Test if the schedule is empty.
Definition
priority-queue-scheduler.cc:60
ns3::Scheduler
Maintain the event list.
Definition
scheduler.h:146
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
event-impl.h
ns3::EventImpl declarations.
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
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:229
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
log-macros-disabled.h
Definition of empty logging macros and the NS_LOG_NOOP_INTERNAL macro.
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 Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0