summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2014-10-16 05:49:46 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2014-10-16 05:49:46 -0400
commitad3f75dc81efc8818786c32d6190e3ed069b9fc6 (patch)
treef3f0e2a55a3fbcd554fb8d4f110e41991de03ae9
parent4e67ab6663f8f4960a1078546906746877f87e1a (diff)
downloadgem5-ad3f75dc81efc8818786c32d6190e3ed069b9fc6.tar.xz
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).
-rw-r--r--src/base/inet.hh10
-rw-r--r--src/dev/etherlink.cc6
-rw-r--r--src/dev/etherpkt.hh5
-rw-r--r--src/dev/ethertap.cc2
-rw-r--r--src/dev/i8254xGBe.cc7
-rw-r--r--src/dev/ns_gige.cc12
-rw-r--r--src/dev/pktfifo.cc2
-rw-r--r--src/dev/sinic.cc6
8 files changed, 26 insertions, 24 deletions
diff --git a/src/base/inet.hh b/src/base/inet.hh
index 5130a072c..07bbdc3b4 100644
--- a/src/base/inet.hh
+++ b/src/base/inet.hh
@@ -182,7 +182,7 @@ class EthPtr
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 @@ class IpPtr
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 @@ class Ip6Ptr
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 @@ class TcpPtr
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 @@ class UdpPtr
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 --git a/src/dev/etherlink.cc b/src/dev/etherlink.cc
index 0117bb7c2..c5ef66d99 100644
--- a/src/dev/etherlink.cc
+++ b/src/dev/etherlink.cc
@@ -195,7 +195,7 @@ EtherLink::Link::transmit(EthPacketPtr pkt)
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 @@ EtherLink::Link::unserialize(const string &base, Checkpoint *cp,
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 @@ LinkDelayEvent::unserialize(Checkpoint *cp, const string &section,
link = parent->link[number];
- packet = new EthPacketData(16384);
+ packet = make_shared<EthPacketData>(16384);
packet->unserialize("packet", cp, section);
}
diff --git a/src/dev/etherpkt.hh b/src/dev/etherpkt.hh
index c71d9cc30..16576d329 100644
--- a/src/dev/etherpkt.hh
+++ b/src/dev/etherpkt.hh
@@ -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 @@ class EthPacketData : public RefCounted
const std::string &section);
};
-typedef RefCountingPtr<EthPacketData> EthPacketPtr;
+typedef std::shared_ptr<EthPacketData> EthPacketPtr;
#endif // __ETHERPKT_HH__
diff --git a/src/dev/ethertap.cc b/src/dev/ethertap.cc
index e14fd90c2..38ce4a2b3 100644
--- a/src/dev/ethertap.cc
+++ b/src/dev/ethertap.cc
@@ -235,7 +235,7 @@ EtherTap::process(int revent)
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 --git a/src/dev/i8254xGBe.cc b/src/dev/i8254xGBe.cc
index d86d7b486..af9734761 100644
--- a/src/dev/i8254xGBe.cc
+++ b/src/dev/i8254xGBe.cc
@@ -41,6 +41,7 @@
*/
#include <algorithm>
+#include <memory>
#include "base/inet.hh"
#include "base/trace.hh"
@@ -2147,7 +2148,7 @@ IGbE::txStateMachine()
}
if (!txPacket) {
- txPacket = new EthPacketData(16384);
+ txPacket = std::make_shared<EthPacketData>(16384);
}
if (!txDescCache.packetWaiting()) {
@@ -2469,7 +2470,7 @@ IGbE::serialize(std::ostream &os)
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 @@ IGbE::unserialize(Checkpoint *cp, const std::string &section)
bool txPktExists;
UNSERIALIZE_SCALAR(txPktExists);
if (txPktExists) {
- txPacket = new EthPacketData(16384);
+ txPacket = std::make_shared<EthPacketData>(16384);
txPacket->unserialize("txpacket", cp, section);
}
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 <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 @@ NSGigE::txKick()
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 @@ 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 &section)
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 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
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 --git a/src/dev/pktfifo.cc b/src/dev/pktfifo.cc
index e5d67d5ec..efd8b083d 100644
--- a/src/dev/pktfifo.cc
+++ b/src/dev/pktfifo.cc
@@ -77,7 +77,7 @@ void
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 --git a/src/dev/sinic.cc b/src/dev/sinic.cc
index 7da70c482..798fb17ef 100644
--- a/src/dev/sinic.cc
+++ b/src/dev/sinic.cc
@@ -1056,7 +1056,7 @@ Device::txKick()
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 @@ Device::serialize(std::ostream &os)
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 @@ Device::unserialize(Checkpoint *cp, const std::string &section)
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);