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).
This commit is contained in:
parent
4e67ab6663
commit
ad3f75dc81
8 changed files with 26 additions and 24 deletions
|
@ -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(); }
|
||||
};
|
||||
|
|
|
@ -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 §ion,
|
|||
|
||||
link = parent->link[number];
|
||||
|
||||
packet = new EthPacketData(16384);
|
||||
packet = make_shared<EthPacketData>(16384);
|
||||
packet->unserialize("packet", cp, section);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 §ion);
|
||||
};
|
||||
|
||||
typedef RefCountingPtr<EthPacketData> EthPacketPtr;
|
||||
typedef std::shared_ptr<EthPacketData> EthPacketPtr;
|
||||
|
||||
#endif // __ETHERPKT_HH__
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 §ion)
|
|||
bool txPktExists;
|
||||
UNSERIALIZE_SCALAR(txPktExists);
|
||||
if (txPktExists) {
|
||||
txPacket = new EthPacketData(16384);
|
||||
txPacket = std::make_shared<EthPacketData>(16384);
|
||||
txPacket->unserialize("txpacket", cp, section);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 §ion)
|
|||
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 §ion)
|
|||
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);
|
||||
|
|
|
@ -77,7 +77,7 @@ void
|
|||
PacketFifoEntry::unserialize(const string &base, Checkpoint *cp,
|
||||
const string §ion)
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -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 §ion)
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue