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 "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
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("PriorityQueueScheduler");
29
30NS_OBJECT_ENSURE_REGISTERED(PriorityQueueScheduler);
31
32TypeId
34{
35 static TypeId tid = TypeId("ns3::PriorityQueueScheduler")
37 .SetGroupName("Core")
38 .AddConstructor<PriorityQueueScheduler>();
39 return tid;
40}
41
46
51
52void
54{
55 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
56 m_queue.push(ev);
57}
58
59bool
61{
62 NS_LOG_FUNCTION(this);
63 return m_queue.empty();
64}
65
68{
69 NS_LOG_FUNCTION(this);
70 return m_queue.top();
71}
72
75{
76 NS_LOG_FUNCTION(this);
77 Scheduler::Event ev = m_queue.top();
78 m_queue.pop();
79 return ev;
80}
81
82bool
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
98void
104
105} // 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:146
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
ns3::EventImpl declarations.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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
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: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