A Discrete-Event Network Simulator
API
priority-queue-scheduler.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 IITP
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alexander Krotov <krotov@iitp.ru>
19  */
20 
22 #include "event-impl.h"
23 #include "assert.h"
24 #include "log-macros-disabled.h"
25 #include "log.h"
26 #include "scheduler.h"
27 #include <string>
28 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("PriorityQueueScheduler");
38 
39 NS_OBJECT_ENSURE_REGISTERED (PriorityQueueScheduler);
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::PriorityQueueScheduler")
45  .SetParent<Scheduler> ()
46  .SetGroupName ("Core")
47  .AddConstructor<PriorityQueueScheduler> ()
48  ;
49  return tid;
50 }
51 
53 {
54  NS_LOG_FUNCTION (this);
55 }
57 {
58  NS_LOG_FUNCTION (this);
59 }
60 
61 void
63 {
64  NS_LOG_FUNCTION (this << ev.impl << ev.key.m_ts << ev.key.m_uid);
65  m_queue.push (ev);
66 }
67 
68 bool
70 {
71  NS_LOG_FUNCTION (this);
72  return m_queue.empty ();
73 }
74 
77 {
78  NS_LOG_FUNCTION (this);
79  return m_queue.top ();
80 }
81 
84 {
85  NS_LOG_FUNCTION (this);
86  Scheduler::Event ev = m_queue.top ();
87  m_queue.pop ();
88  return ev;
89 }
90 
91 bool
93 {
94  auto it = std::find(this->c.begin(), this->c.end(), ev);
95  if (it != this->c.end())
96  {
97  this->c.erase(it);
98  std::make_heap(this->c.begin(), this->c.end(), this->comp);
99  return true;
100  }
101  else
102  {
103  return false;
104  }
105 }
106 
107 void
109 {
110  NS_LOG_FUNCTION (this);
111  m_queue.remove (ev);
112 }
113 
114 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:183
ns3::PriorityQueueScheduler::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: priority-queue-scheduler.cc:42
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:92
ns3::PriorityQueueScheduler::RemoveNext
virtual Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
Definition: priority-queue-scheduler.cc:83
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
scheduler.h
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::Scheduler::EventKey::m_ts
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:170
ns3::PriorityQueueScheduler::IsEmpty
virtual bool IsEmpty(void) const
Test if the schedule is empty.
Definition: priority-queue-scheduler.cc:69
ns3::Scheduler::Event
Scheduler event.
Definition: scheduler.h:182
ns3::PriorityQueueScheduler::PeekNext
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
Definition: priority-queue-scheduler.cc:76
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:184
priority-queue-scheduler.h
Declaration of ns3::PriorityQueueScheduler class.
ns3::PriorityQueueScheduler::Insert
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
Definition: priority-queue-scheduler.cc:62
event-impl.h
ns3::EventImpl declarations.
ns3::PriorityQueueScheduler
a std::priority_queue event scheduler
Definition: priority-queue-scheduler.h:65
ns3::PriorityQueueScheduler::PriorityQueueScheduler
PriorityQueueScheduler()
Constructor.
Definition: priority-queue-scheduler.cc:52
log.h
Debug message logging.
ns3::PriorityQueueScheduler::Remove
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
Definition: priority-queue-scheduler.cc:108
ns3::Scheduler
Maintain the event list.
Definition: scheduler.h:156
ns3::PriorityQueueScheduler::m_queue
EventPriorityQueue m_queue
The event queue.
Definition: priority-queue-scheduler.h:107
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:244
log-macros-disabled.h
Definition of empty logging macros and the NS_LOG_NOOP_INTERNAL macro.
ns3::PriorityQueueScheduler::~PriorityQueueScheduler
virtual ~PriorityQueueScheduler()
Destructor.
Definition: priority-queue-scheduler.cc:56
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition: scheduler.h:171