changeset b16b7dc83139 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=b16b7dc83139
description:
        dev: Use shared_ptr for EthPacketData

        This patch transitions the EthPacketData from the ad-hoc
        RefCountingPtr to the c++11 shared_ptr. There are no changes in
        behaviour, and the code modifications are mainly replacing "new" with
        "make_shared".

        The bool casting operator for the shared_ptr is explicit, and we must
        therefore either cast it, compare it to NULL (p != nullptr), double
        negate it (!!p) or do a (p ? true : false).

diffstat:

 src/base/inet.hh     |  10 +++++-----
 src/dev/etherlink.cc |   6 +++---
 src/dev/etherpkt.hh  |   5 ++---
 src/dev/ethertap.cc  |   2 +-
 src/dev/i8254xGBe.cc |   7 ++++---
 src/dev/ns_gige.cc   |  12 +++++++-----
 src/dev/pktfifo.cc   |   2 +-
 src/dev/sinic.cc     |   6 +++---
 8 files changed, 26 insertions(+), 24 deletions(-)

diffs (261 lines):

diff -r 8c1b836edc92 -r b16b7dc83139 src/base/inet.hh
--- a/src/base/inet.hh  Thu Oct 16 05:49:45 2014 -0400
+++ b/src/base/inet.hh  Thu Oct 16 05:49:46 2014 -0400
@@ -182,7 +182,7 @@
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
-    operator bool() const { return p; }
+    operator bool() const { return (p != nullptr); }
     int off() const { return 0; }
     int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
 };
@@ -324,7 +324,7 @@
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
-    operator bool() const { return p; }
+    operator bool() const { return (p != nullptr); }
     int off() const { return (sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0)); }
     int pstart() const { return (off() + get()->size()); }
 };
@@ -440,7 +440,7 @@
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
-    operator bool() const { return p; }
+    operator bool() const { return (p != nullptr); }
     int off() const { return sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0); }
     int pstart() const { return off() + get()->size(); }
 };
@@ -576,7 +576,7 @@
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
-    operator bool() const { return p; }
+    operator bool() const { return (p != nullptr); }
     int off() const { return _off; }
     int pstart() const { return off() + get()->size(); }
 };
@@ -671,7 +671,7 @@
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
-    operator bool() const { return p; }
+    operator bool() const { return (p != nullptr); }
     int off() const { return _off; }
     int pstart() const { return off() + get()->size(); }
 };
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/etherlink.cc
--- a/src/dev/etherlink.cc      Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/etherlink.cc      Thu Oct 16 05:49:46 2014 -0400
@@ -195,7 +195,7 @@
 void
 EtherLink::Link::serialize(const string &base, ostream &os)
 {
-    bool packet_exists = packet;
+    bool packet_exists = packet != nullptr;
     paramOut(os, base + ".packet_exists", packet_exists);
     if (packet_exists)
         packet->serialize(base + ".packet", os);
@@ -216,7 +216,7 @@
     bool packet_exists;
     paramIn(cp, section, base + ".packet_exists", packet_exists);
     if (packet_exists) {
-        packet = new EthPacketData(16384);
+        packet = make_shared<EthPacketData>(16384);
         packet->unserialize(base + ".packet", cp, section);
     }
 
@@ -273,7 +273,7 @@
 
     link = parent->link[number];
 
-    packet = new EthPacketData(16384);
+    packet = make_shared<EthPacketData>(16384);
     packet->unserialize("packet", cp, section);
 }
 
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/etherpkt.hh
--- a/src/dev/etherpkt.hh       Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/etherpkt.hh       Thu Oct 16 05:49:46 2014 -0400
@@ -40,14 +40,13 @@
 #include <iosfwd>
 #include <memory>
 
-#include "base/refcnt.hh"
 #include "base/types.hh"
 
 /*
  * Reference counted class containing ethernet packet data
  */
 class Checkpoint;
-class EthPacketData : public RefCounted
+class EthPacketData
 {
   public:
     /*
@@ -81,6 +80,6 @@
                      const std::string &section);
 };
 
-typedef RefCountingPtr<EthPacketData> EthPacketPtr;
+typedef std::shared_ptr<EthPacketData> EthPacketPtr;
 
 #endif // __ETHERPKT_HH__
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/ethertap.cc
--- a/src/dev/ethertap.cc       Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/ethertap.cc       Thu Oct 16 05:49:46 2014 -0400
@@ -235,7 +235,7 @@
 
     while (data_len != 0 && buffer_offset >= data_len + sizeof(uint32_t)) {
         EthPacketPtr packet;
-        packet = new EthPacketData(data_len);
+        packet = make_shared<EthPacketData>(data_len);
         packet->length = data_len;
         memcpy(packet->data, data, data_len);
 
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/i8254xGBe.cc
--- a/src/dev/i8254xGBe.cc      Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/i8254xGBe.cc      Thu Oct 16 05:49:46 2014 -0400
@@ -41,6 +41,7 @@
  */
 
 #include <algorithm>
+#include <memory>
 
 #include "base/inet.hh"
 #include "base/trace.hh"
@@ -2147,7 +2148,7 @@
     }
 
     if (!txPacket) {
-        txPacket = new EthPacketData(16384);
+        txPacket = std::make_shared<EthPacketData>(16384);
     }
 
     if (!txDescCache.packetWaiting()) {
@@ -2469,7 +2470,7 @@
     rxFifo.serialize("rxfifo", os);
     txFifo.serialize("txfifo", os);
 
-    bool txPktExists = txPacket;
+    bool txPktExists = txPacket != nullptr;
     SERIALIZE_SCALAR(txPktExists);
     if (txPktExists)
         txPacket->serialize("txpacket", os);
@@ -2526,7 +2527,7 @@
     bool txPktExists;
     UNSERIALIZE_SCALAR(txPktExists);
     if (txPktExists) {
-        txPacket = new EthPacketData(16384);
+        txPacket = std::make_shared<EthPacketData>(16384);
         txPacket->unserialize("txpacket", cp, section);
     }
 
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/ns_gige.cc
--- a/src/dev/ns_gige.cc        Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/ns_gige.cc        Thu Oct 16 05:49:46 2014 -0400
@@ -34,6 +34,7 @@
  * DP83820 ethernet controller.  Does not support priority queueing
  */
 #include <deque>
+#include <memory>
 #include <string>
 
 #include "base/debug.hh"
@@ -51,6 +52,7 @@
 
 // clang complains about std::set being overloaded with Packet::set if
 // we open up the entire namespace std
+using std::make_shared;
 using std::min;
 using std::ostream;
 using std::string;
@@ -1676,7 +1678,7 @@
       case txFifoBlock:
         if (!txPacket) {
             DPRINTF(EthernetSM, "****starting the tx of a new packet****\n");
-            txPacket = new EthPacketData(16384);
+            txPacket = make_shared<EthPacketData>(16384);
             txPacketBufPtr = txPacket->data;
         }
 
@@ -2185,7 +2187,7 @@
     /*
      * Serialize the various helper variables
      */
-    bool txPacketExists = txPacket;
+    bool txPacketExists = txPacket != nullptr;
     SERIALIZE_SCALAR(txPacketExists);
     if (txPacketExists) {
         txPacket->length = txPacketBufPtr - txPacket->data;
@@ -2194,7 +2196,7 @@
         SERIALIZE_SCALAR(txPktBufPtr);
     }
 
-    bool rxPacketExists = rxPacket;
+    bool rxPacketExists = rxPacket != nullptr;
     SERIALIZE_SCALAR(rxPacketExists);
     if (rxPacketExists) {
         rxPacket->serialize("rxPacket", os);
@@ -2352,7 +2354,7 @@
     bool txPacketExists;
     UNSERIALIZE_SCALAR(txPacketExists);
     if (txPacketExists) {
-        txPacket = new EthPacketData(16384);
+        txPacket = make_shared<EthPacketData>(16384);
         txPacket->unserialize("txPacket", cp, section);
         uint32_t txPktBufPtr;
         UNSERIALIZE_SCALAR(txPktBufPtr);
@@ -2364,7 +2366,7 @@
     UNSERIALIZE_SCALAR(rxPacketExists);
     rxPacket = 0;
     if (rxPacketExists) {
-        rxPacket = new EthPacketData(16384);
+        rxPacket = make_shared<EthPacketData>(16384);
         rxPacket->unserialize("rxPacket", cp, section);
         uint32_t rxPktBufPtr;
         UNSERIALIZE_SCALAR(rxPktBufPtr);
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/pktfifo.cc
--- a/src/dev/pktfifo.cc        Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/pktfifo.cc        Thu Oct 16 05:49:46 2014 -0400
@@ -77,7 +77,7 @@
 PacketFifoEntry::unserialize(const string &base, Checkpoint *cp,
                              const string &section)
 {
-    packet = new EthPacketData(16384);
+    packet = make_shared<EthPacketData>(16384);
     packet->unserialize(base + ".packet", cp, section);
     paramIn(cp, section, base + ".slack", slack);
     paramIn(cp, section, base + ".number", number);
diff -r 8c1b836edc92 -r b16b7dc83139 src/dev/sinic.cc
--- a/src/dev/sinic.cc  Thu Oct 16 05:49:45 2014 -0400
+++ b/src/dev/sinic.cc  Thu Oct 16 05:49:46 2014 -0400
@@ -1056,7 +1056,7 @@
         assert(Regs::get_TxDone_Busy(vnic->TxDone));
         if (!txPacket) {
             // Grab a new packet from the fifo.
-            txPacket = new EthPacketData(16384);
+            txPacket = make_shared<EthPacketData>(16384);
             txPacketOffset = 0;
         }
 
@@ -1403,7 +1403,7 @@
     SERIALIZE_SCALAR(txState);
     SERIALIZE_SCALAR(txFull);
     txFifo.serialize("txFifo", os);
-    bool txPacketExists = txPacket;
+    bool txPacketExists = txPacket != nullptr;
     SERIALIZE_SCALAR(txPacketExists);
     if (txPacketExists) {
         txPacket->serialize("txPacket", os);
@@ -1498,7 +1498,7 @@
     UNSERIALIZE_SCALAR(txPacketExists);
     txPacket = 0;
     if (txPacketExists) {
-        txPacket = new EthPacketData(16384);
+        txPacket = make_shared<EthPacketData>(16384);
         txPacket->unserialize("txPacket", cp, section);
         UNSERIALIZE_SCALAR(txPacketOffset);
         UNSERIALIZE_SCALAR(txPacketBytes);
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to