diff options
author | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2018-06-04 09:40:19 +0100 |
---|---|---|
committer | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2018-06-11 16:55:30 +0000 |
commit | f54020eb8155371725ab75b0fc5c419287eca084 (patch) | |
tree | 65d379f7603e689e083e9a58ff4c2e90abd19fbf /src/mem/packet.hh | |
parent | 2113b21996d086dab32b9fd388efe3df241bfbd2 (diff) | |
download | gem5-f54020eb8155371725ab75b0fc5c419287eca084.tar.xz |
misc: Using smart pointers for memory Requests
This patch is changing the underlying type for RequestPtr from Request*
to shared_ptr<Request>. Having memory requests being managed by smart
pointers will simplify the code; it will also prevent memory leakage and
dangling pointers.
Change-Id: I7749af38a11ac8eb4d53d8df1252951e0890fde3
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/10996
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src/mem/packet.hh')
-rw-r--r-- | src/mem/packet.hh | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/src/mem/packet.hh b/src/mem/packet.hh index a4eeabe29..5bc466bf1 100644 --- a/src/mem/packet.hh +++ b/src/mem/packet.hh @@ -320,7 +320,7 @@ class Packet : public Printable const PacketId id; /// A pointer to the original request. - const RequestPtr req; + RequestPtr req; private: /** @@ -745,9 +745,9 @@ class Packet : public Printable * first, but the Requests's physical address and size fields need * not be valid. The command must be supplied. */ - Packet(const RequestPtr _req, MemCmd _cmd) - : cmd(_cmd), id((PacketId)_req), req(_req), data(nullptr), addr(0), - _isSecure(false), size(0), headerDelay(0), snoopDelay(0), + Packet(const RequestPtr &_req, MemCmd _cmd) + : cmd(_cmd), id((PacketId)_req.get()), req(_req), data(nullptr), + addr(0), _isSecure(false), size(0), headerDelay(0), snoopDelay(0), payloadDelay(0), senderState(NULL) { if (req->hasPaddr()) { @@ -766,10 +766,10 @@ class Packet : public Printable * a request that is for a whole block, not the address from the * req. this allows for overriding the size/addr of the req. */ - Packet(const RequestPtr _req, MemCmd _cmd, int _blkSize, PacketId _id = 0) - : cmd(_cmd), id(_id ? _id : (PacketId)_req), req(_req), data(nullptr), - addr(0), _isSecure(false), headerDelay(0), snoopDelay(0), - payloadDelay(0), senderState(NULL) + Packet(const RequestPtr &_req, MemCmd _cmd, int _blkSize, PacketId _id = 0) + : cmd(_cmd), id(_id ? _id : (PacketId)_req.get()), req(_req), + data(nullptr), addr(0), _isSecure(false), headerDelay(0), + snoopDelay(0), payloadDelay(0), senderState(NULL) { if (req->hasPaddr()) { addr = req->getPaddr() & ~(_blkSize - 1); @@ -823,7 +823,7 @@ class Packet : public Printable * Generate the appropriate read MemCmd based on the Request flags. */ static MemCmd - makeReadCmd(const RequestPtr req) + makeReadCmd(const RequestPtr &req) { if (req->isLLSC()) return MemCmd::LoadLockedReq; @@ -837,7 +837,7 @@ class Packet : public Printable * Generate the appropriate write MemCmd based on the Request flags. */ static MemCmd - makeWriteCmd(const RequestPtr req) + makeWriteCmd(const RequestPtr &req) { if (req->isLLSC()) return MemCmd::StoreCondReq; @@ -857,13 +857,13 @@ class Packet : public Printable * Fine-tune the MemCmd type if it's not a vanilla read or write. */ static PacketPtr - createRead(const RequestPtr req) + createRead(const RequestPtr &req) { return new Packet(req, makeReadCmd(req)); } static PacketPtr - createWrite(const RequestPtr req) + createWrite(const RequestPtr &req) { return new Packet(req, makeWriteCmd(req)); } @@ -873,18 +873,6 @@ class Packet : public Printable */ ~Packet() { - // Delete the request object if this is a request packet which - // does not need a response, because the requester will not get - // a chance. If the request packet needs a response then the - // request will be deleted on receipt of the response - // packet. We also make sure to never delete the request for - // express snoops, even for cases when responses are not - // needed (CleanEvict and Writeback), since the snoop packet - // re-uses the same request. - if (req && isRequest() && !needsResponse() && - !isExpressSnoop()) { - delete req; - } deleteData(); } |