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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Alexander Krotov <krotov@iitp.ru>
7 */
8
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
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("PriorityQueueScheduler");
26
28
31{
32 static TypeId tid = TypeId("ns3::PriorityQueueScheduler")
34 .SetGroupName("Core")
35 .AddConstructor<PriorityQueueScheduler>();
36 return tid;
37}
38
43
48
49void
51{
52 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
53 m_queue.push(ev);
54}
55
56bool
58{
59 NS_LOG_FUNCTION(this);
60 return m_queue.empty();
61}
62
65{
66 NS_LOG_FUNCTION(this);
67 return m_queue.top();
68}
69
72{
73 NS_LOG_FUNCTION(this);
74 Scheduler::Event ev = m_queue.top();
75 m_queue.pop();
76 return ev;
77}
78
79bool
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
95void
97{
98 NS_LOG_FUNCTION(this);
99 m_queue.remove(ev);
100}
101
102} // namespace ns3
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:146
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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:35
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:173
EventKey key
Key for sorting and ordering Events.
Definition scheduler.h:175
EventImpl * impl
Pointer to the event implementation.
Definition scheduler.h:174
uint64_t m_ts
Event time stamp.
Definition scheduler.h:160
uint32_t m_uid
Event unique id.
Definition scheduler.h:161