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
* 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
20
#include "
priority-queue-scheduler.h
"
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
36
namespace
ns3
37
{
38
39
NS_LOG_COMPONENT_DEFINE
(
"PriorityQueueScheduler"
);
40
41
NS_OBJECT_ENSURE_REGISTERED
(PriorityQueueScheduler);
42
43
TypeId
44
PriorityQueueScheduler::GetTypeId
()
45
{
46
static
TypeId
tid =
TypeId
(
"ns3::PriorityQueueScheduler"
)
47
.
SetParent
<
Scheduler
>()
48
.SetGroupName(
"Core"
)
49
.AddConstructor<
PriorityQueueScheduler
>();
50
return
tid;
51
}
52
53
PriorityQueueScheduler::PriorityQueueScheduler
()
54
{
55
NS_LOG_FUNCTION
(
this
);
56
}
57
58
PriorityQueueScheduler::~PriorityQueueScheduler
()
59
{
60
NS_LOG_FUNCTION
(
this
);
61
}
62
63
void
64
PriorityQueueScheduler::Insert
(
const
Event
& ev)
65
{
66
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
67
m_queue
.push(ev);
68
}
69
70
bool
71
PriorityQueueScheduler::IsEmpty
()
const
72
{
73
NS_LOG_FUNCTION
(
this
);
74
return
m_queue
.empty();
75
}
76
77
Scheduler::Event
78
PriorityQueueScheduler::PeekNext
()
const
79
{
80
NS_LOG_FUNCTION
(
this
);
81
return
m_queue
.top();
82
}
83
84
Scheduler::Event
85
PriorityQueueScheduler::RemoveNext
()
86
{
87
NS_LOG_FUNCTION
(
this
);
88
Scheduler::Event
ev =
m_queue
.top();
89
m_queue
.pop();
90
return
ev;
91
}
92
93
bool
94
PriorityQueueScheduler::EventPriorityQueue::remove
(
const
Scheduler::Event
& ev)
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
109
void
110
PriorityQueueScheduler::Remove
(
const
Scheduler::Event
& ev)
111
{
112
NS_LOG_FUNCTION
(
this
);
113
m_queue
.
remove
(ev);
114
}
115
116
}
// 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:94
ns3::PriorityQueueScheduler
a std::priority_queue event scheduler
Definition:
priority-queue-scheduler.h:66
ns3::PriorityQueueScheduler::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
priority-queue-scheduler.cc:44
ns3::PriorityQueueScheduler::RemoveNext
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Definition:
priority-queue-scheduler.cc:85
ns3::PriorityQueueScheduler::~PriorityQueueScheduler
~PriorityQueueScheduler() override
Destructor.
Definition:
priority-queue-scheduler.cc:58
ns3::PriorityQueueScheduler::Insert
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Definition:
priority-queue-scheduler.cc:64
ns3::PriorityQueueScheduler::PeekNext
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
Definition:
priority-queue-scheduler.cc:78
ns3::PriorityQueueScheduler::Remove
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
Definition:
priority-queue-scheduler.cc:110
ns3::PriorityQueueScheduler::m_queue
EventPriorityQueue m_queue
The event queue.
Definition:
priority-queue-scheduler.h:105
ns3::PriorityQueueScheduler::PriorityQueueScheduler
PriorityQueueScheduler()
Constructor.
Definition:
priority-queue-scheduler.cc:53
ns3::PriorityQueueScheduler::IsEmpty
bool IsEmpty() const override
Test if the schedule is empty.
Definition:
priority-queue-scheduler.cc:71
ns3::Scheduler
Maintain the event list.
Definition:
scheduler.h:157
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:936
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:202
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:238
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
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:184
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition:
scheduler.h:186
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition:
scheduler.h:185
ns3::Scheduler::EventKey::m_ts
uint64_t m_ts
Event time stamp.
Definition:
scheduler.h:171
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition:
scheduler.h:172
src
core
model
priority-queue-scheduler.cc
Generated on Sun Jul 2 2023 18:21:32 for ns-3 by
1.9.6