From ad3f75dc81efc8818786c32d6190e3ed069b9fc6 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Thu, 16 Oct 2014 05:49:46 -0400 Subject: 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). --- src/dev/ns_gige.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/dev/ns_gige.cc') diff --git a/src/dev/ns_gige.cc b/src/dev/ns_gige.cc index f180b0ecd..239babe70 100644 --- a/src/dev/ns_gige.cc +++ b/src/dev/ns_gige.cc @@ -34,6 +34,7 @@ * DP83820 ethernet controller. Does not support priority queueing */ #include +#include #include #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 @@ NSGigE::txKick() case txFifoBlock: if (!txPacket) { DPRINTF(EthernetSM, "****starting the tx of a new packet****\n"); - txPacket = new EthPacketData(16384); + txPacket = make_shared(16384); txPacketBufPtr = txPacket->data; } @@ -2185,7 +2187,7 @@ NSGigE::serialize(ostream &os) /* * 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 @@ NSGigE::serialize(ostream &os) SERIALIZE_SCALAR(txPktBufPtr); } - bool rxPacketExists = rxPacket; + bool rxPacketExists = rxPacket != nullptr; SERIALIZE_SCALAR(rxPacketExists); if (rxPacketExists) { rxPacket->serialize("rxPacket", os); @@ -2352,7 +2354,7 @@ NSGigE::unserialize(Checkpoint *cp, const std::string §ion) bool txPacketExists; UNSERIALIZE_SCALAR(txPacketExists); if (txPacketExists) { - txPacket = new EthPacketData(16384); + txPacket = make_shared(16384); txPacket->unserialize("txPacket", cp, section); uint32_t txPktBufPtr; UNSERIALIZE_SCALAR(txPktBufPtr); @@ -2364,7 +2366,7 @@ NSGigE::unserialize(Checkpoint *cp, const std::string §ion) UNSERIALIZE_SCALAR(rxPacketExists); rxPacket = 0; if (rxPacketExists) { - rxPacket = new EthPacketData(16384); + rxPacket = make_shared(16384); rxPacket->unserialize("rxPacket", cp, section); uint32_t rxPktBufPtr; UNSERIALIZE_SCALAR(rxPktBufPtr); -- cgit v1.2.3