-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriorityqueue.h
44 lines (35 loc) · 853 Bytes
/
priorityqueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef PRIORITY_QUEUE_H
#define PRIORITY_QUEUE_H
/*
* A priority-queue that drains packets based on their priority.
*/
#include "queue.h"
#include <set>
class ComparePacketPriority
{
public:
bool operator() (Packet *a, Packet *b)
{
if (a->getPriority() < b->getPriority()) {
return true;
} else {
return false;
}
}
};
class PriorityQueue : public Queue
{
public:
PriorityQueue(linkspeed_bps bitrate, mem_b maxsize, QueueLogger *logger);
void receivePacket(Packet &pkt);
void printStats();
protected:
void beginService();
void completeService();
private:
// Multi-set of all packets, to transmit from head or drop from tail.
std::multiset<Packet*, ComparePacketPriority> _packets;
// Current packet being serviced.
Packet *_currentPkt;
};
#endif