diff options
author | Nathan Binkert <binkertn@umich.edu> | 2005-11-25 11:22:41 -0500 |
---|---|---|
committer | Nathan Binkert <binkertn@umich.edu> | 2005-11-25 11:22:41 -0500 |
commit | 60e92986f739a025a6534972b8e1cf9498ce3fd2 (patch) | |
tree | 8a521054aa240858ed0f2840a53e361df4d2e269 /dev/pktfifo.hh | |
parent | c0a4836077425e03cc39dfba88bec7da21af950b (diff) | |
download | gem5-60e92986f739a025a6534972b8e1cf9498ce3fd2.tar.xz |
Add the capability to iterate through the packets in a pktfifo,
and to remove elements in the middle of the fifo. These elements
do not free space, they are just marked removed. Space is only
freed from the front of the fifo.
dev/etherpkt.cc:
serialize the current slack
dev/etherpkt.hh:
add "slack" to the ethernet packet. It is to be used by any fifo that
the packet is currently in to account for extra space that the packet
may be occupying due to the fifo organization.
--HG--
extra : convert_revision : 8e7c541ba316a9a76495c54cc5f707f8fc65b6d5
Diffstat (limited to 'dev/pktfifo.hh')
-rw-r--r-- | dev/pktfifo.hh | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/dev/pktfifo.hh b/dev/pktfifo.hh index a8b626618..61e4ead1b 100644 --- a/dev/pktfifo.hh +++ b/dev/pktfifo.hh @@ -39,6 +39,10 @@ class Checkpoint; class PacketFifo { + public: + typedef std::list<PacketPtr> fifo_list; + typedef fifo_list::iterator iterator; + protected: std::list<PacketPtr> fifo; int _maxsize; @@ -64,9 +68,16 @@ class PacketFifo return _reserved; } + iterator begin() { return fifo.begin(); } + iterator end() { return fifo.end(); } + + PacketPtr front() { return fifo.front(); } + bool push(PacketPtr ptr) { + assert(ptr->length); assert(_reserved <= ptr->length); + assert(ptr->slack == 0); if (avail() < ptr->length - _reserved) return false; @@ -76,25 +87,44 @@ class PacketFifo return true; } - PacketPtr front() { return fifo.front(); } - void pop() { if (empty()) return; - _size -= fifo.front()->length; - fifo.front() = NULL; + PacketPtr &packet = fifo.front(); + _size -= packet->length; + _size -= packet->slack; + packet->slack = 0; + packet = NULL; fifo.pop_front(); } void clear() { + for (iterator i = begin(); i != end(); ++i) + (*i)->slack = 0; fifo.clear(); _size = 0; _reserved = 0; } + void remove(iterator i) + { + PacketPtr &packet = *i; + if (i != fifo.begin()) { + --i; + (*i)->slack += packet->length; + } else { + _size -= packet->length; + _size -= packet->slack; + } + + packet->slack = 0; + packet = NULL; + fifo.erase(i); + } + /** * Serialization stuff */ |