From: Andreas Hansson Date: Thu, 16 Oct 2014 09:49:49 +0000 (-0400) Subject: mem: Use shared_ptr for Ruby Message classes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=db3739682d7c54839b627ff8f7a4448a9dc99987;p=gem5.git mem: Use shared_ptr for Ruby Message classes This patch transitions the Ruby Message and its derived classes 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 cloning of derived messages is slightly changed as they previously relied on overriding the base-class through covariant return types. --- diff --git a/src/mem/ruby/slicc_interface/Message.hh b/src/mem/ruby/slicc_interface/Message.hh index 1c842ae69..786c656bc 100644 --- a/src/mem/ruby/slicc_interface/Message.hh +++ b/src/mem/ruby/slicc_interface/Message.hh @@ -30,14 +30,14 @@ #define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ #include +#include -#include "base/refcnt.hh" #include "mem/packet.hh" class Message; -typedef RefCountingPtr MsgPtr; +typedef std::shared_ptr MsgPtr; -class Message : public RefCounted +class Message { public: Message(Tick curTime) @@ -54,7 +54,7 @@ class Message : public RefCounted virtual ~Message() { } - virtual Message* clone() const = 0; + virtual MsgPtr clone() const = 0; virtual void print(std::ostream& out) const = 0; virtual void setIncomingLink(int) {} virtual void setVnet(int) {} diff --git a/src/mem/ruby/slicc_interface/NetworkMessage.hh b/src/mem/ruby/slicc_interface/NetworkMessage.hh index 10d78251a..1b5edcfcd 100644 --- a/src/mem/ruby/slicc_interface/NetworkMessage.hh +++ b/src/mem/ruby/slicc_interface/NetworkMessage.hh @@ -30,13 +30,14 @@ #define __MEM_RUBY_SLICC_INTERFACE_NETWORKMESSAGE_HH__ #include +#include #include "mem/protocol/MessageSizeType.hh" #include "mem/ruby/common/NetDest.hh" #include "mem/ruby/slicc_interface/Message.hh" class NetworkMessage; -typedef RefCountingPtr NetMsgPtr; +typedef std::shared_ptr NetMsgPtr; class NetworkMessage : public Message { diff --git a/src/mem/ruby/slicc_interface/RubyRequest.hh b/src/mem/ruby/slicc_interface/RubyRequest.hh index 49964ebb9..357eddbb5 100644 --- a/src/mem/ruby/slicc_interface/RubyRequest.hh +++ b/src/mem/ruby/slicc_interface/RubyRequest.hh @@ -71,7 +71,8 @@ class RubyRequest : public Message } RubyRequest(Tick curTime) : Message(curTime) {} - RubyRequest* clone() const { return new RubyRequest(*this); } + MsgPtr clone() const + { return std::shared_ptr(new RubyRequest(*this)); } const Address& getLineAddress() const { return m_LineAddress; } const Address& getPhysicalAddress() const { return m_PhysicalAddress; } diff --git a/src/mem/ruby/system/DMASequencer.cc b/src/mem/ruby/system/DMASequencer.cc index 9b0157b45..2a458a408 100644 --- a/src/mem/ruby/system/DMASequencer.cc +++ b/src/mem/ruby/system/DMASequencer.cc @@ -26,6 +26,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #include "debug/RubyDma.hh" #include "debug/RubyStats.hh" #include "mem/protocol/SequencerMsg.hh" @@ -69,7 +71,8 @@ DMASequencer::makeRequest(PacketPtr pkt) active_request.bytes_issued = 0; active_request.pkt = pkt; - SequencerMsg *msg = new SequencerMsg(clockEdge()); + std::shared_ptr msg = + std::make_shared(clockEdge()); msg->getPhysicalAddress() = Address(paddr); msg->getLineAddress() = line_address(msg->getPhysicalAddress()); msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; @@ -107,7 +110,8 @@ DMASequencer::issueNext() return; } - SequencerMsg *msg = new SequencerMsg(clockEdge()); + std::shared_ptr msg = + std::make_shared(clockEdge()); msg->getPhysicalAddress() = Address(active_request.start_paddr + active_request.bytes_completed); diff --git a/src/mem/ruby/system/DMASequencer.hh b/src/mem/ruby/system/DMASequencer.hh index b3ba0be8c..13d79182d 100644 --- a/src/mem/ruby/system/DMASequencer.hh +++ b/src/mem/ruby/system/DMASequencer.hh @@ -30,6 +30,7 @@ #define __MEM_RUBY_SYSTEM_DMASEQUENCER_HH__ #include +#include #include "mem/protocol/DMASequencerRequestType.hh" #include "mem/ruby/common/DataBlock.hh" diff --git a/src/mem/ruby/system/Sequencer.cc b/src/mem/ruby/system/Sequencer.cc index dcdaf6a6f..bd82d9468 100644 --- a/src/mem/ruby/system/Sequencer.cc +++ b/src/mem/ruby/system/Sequencer.cc @@ -679,11 +679,12 @@ Sequencer::issueRequest(PacketPtr pkt, RubyRequestType secondary_type) pc = pkt->req->getPC(); } - RubyRequest *msg = new RubyRequest(clockEdge(), pkt->getAddr(), - pkt->getPtr(true), - pkt->getSize(), pc, secondary_type, - RubyAccessMode_Supervisor, pkt, - PrefetchBit_No, proc_id); + std::shared_ptr msg = + std::make_shared(clockEdge(), pkt->getAddr(), + pkt->getPtr(true), + pkt->getSize(), pc, secondary_type, + RubyAccessMode_Supervisor, pkt, + PrefetchBit_No, proc_id); DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\n", curTick(), m_version, "Seq", "Begin", "", "", diff --git a/src/mem/slicc/ast/EnqueueStatementAST.py b/src/mem/slicc/ast/EnqueueStatementAST.py index c4f2ac06c..e08e49808 100644 --- a/src/mem/slicc/ast/EnqueueStatementAST.py +++ b/src/mem/slicc/ast/EnqueueStatementAST.py @@ -54,8 +54,8 @@ class EnqueueStatementAST(StatementAST): self.symtab.newSymbol(v) # Declare message - code("${{msg_type.ident}} *out_msg = "\ - "new ${{msg_type.ident}}(clockEdge());") + code("std::shared_ptr<${{msg_type.ident}}> out_msg = "\ + "std::make_shared<${{msg_type.ident}}>(clockEdge());") # The other statements t = self.statements.generate(code, None) diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py index d9bd85c01..2afd9958c 100644 --- a/src/mem/slicc/symbols/Type.py +++ b/src/mem/slicc/symbols/Type.py @@ -283,7 +283,16 @@ $klass ${{self.c_ident}}$parent code('}') # create a clone member - code(''' + if self.isMessage: + code(''' +MsgPtr +clone() const +{ + return std::shared_ptr(new ${{self.c_ident}}(*this)); +} +''') + else: + code(''' ${{self.c_ident}}* clone() const { @@ -391,6 +400,7 @@ operator<<(std::ostream& out, const ${{self.c_ident}}& obj) */ #include +#include #include "mem/protocol/${{self.c_ident}}.hh" #include "mem/ruby/common/Global.hh"