Changed the hello_sparc executable back to the cross compiled one
[gem5.git] / dev / pktfifo.hh
index 0c237949c7d5f8dc678d4c83034852ec99570231..e245840a80b88e4a4623d7354dc2e9a8ff590dfd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002-2004 The Regents of The University of Michigan
+ * Copyright (c) 2004-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 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,75 @@ 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()) {
+            iterator prev = i;
+            --prev;
+            assert(prev != fifo.end());
+            (*prev)->slack += packet->length;
+        } else {
+            _size -= packet->length;
+            _size -= packet->slack;
+        }
+
+        packet->slack = 0;
+        packet = NULL;
+        fifo.erase(i);
+    }
+
+    bool copyout(void *dest, int offset, int len);
+
+    int countPacketsBefore(iterator end)
+    {
+        iterator i = fifo.begin();
+        int count = 0;
+
+        while (i != end) {
+            ++count;
+            ++i;
+        }
+
+        return count;
+    }
+
+    int countPacketsAfter(iterator i)
+    {
+        iterator end = fifo.end();
+        int count = 0;
+
+        while (i != end) {
+            ++count;
+            ++i;
+        }
+
+        return count;
+    }
+
+
 /**
  * Serialization stuff
  */