From bc87fa30d72df7db6265be50b2c39dc218076f9f Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 10 Jun 2010 23:17:06 -0700 Subject: ruby: get rid of RefCnt and Allocator stuff use base/refcnt.hh This was somewhat tricky because the RefCnt API was somewhat odd. The biggest confusion was that the the RefCnt object's constructor that took a TYPE& cloned the object. I created an explicit virtual clone() function for things that took advantage of this version of the constructor. I was conservative and used clone() when I was in doubt of whether or not it was necessary. I still think that there are probably too many instances of clone(), but hopefully not too many. I converted several instances of const MsgPtr & to a simple MsgPtr. If the function wants to avoid the overhead of creating another reference, then it should just use a regular pointer instead of a ref counting ptr. There were a couple of instances where refcounted objects were created on the stack. This seems pretty dangerous since if you ever accidentally make a reference to that object with a ref counting pointer, bad things are bound to happen. --- src/mem/ruby/slicc_interface/Message.hh | 24 +++++++++++++----------- src/mem/ruby/slicc_interface/NetworkMessage.hh | 15 ++++++++------- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src/mem/ruby/slicc_interface') diff --git a/src/mem/ruby/slicc_interface/Message.hh b/src/mem/ruby/slicc_interface/Message.hh index d9df6f131..ff94fdd40 100644 --- a/src/mem/ruby/slicc_interface/Message.hh +++ b/src/mem/ruby/slicc_interface/Message.hh @@ -31,29 +31,31 @@ #include -#include "mem/gems_common/RefCnt.hh" -#include "mem/gems_common/RefCountable.hh" +#include "base/refcnt.hh" #include "mem/ruby/common/Global.hh" #include "mem/ruby/eventqueue/RubyEventQueue.hh" class Message; -typedef RefCnt MsgPtr; +typedef RefCountingPtr MsgPtr; -class Message : public RefCountable +class Message : public RefCounted { public: Message() - : RefCountable() - { - m_time = g_eventQueue_ptr->getTime(); - m_LastEnqueueTime = g_eventQueue_ptr->getTime(); - m_DelayedCycles = 0; - } + : m_time(g_eventQueue_ptr->getTime()), + m_LastEnqueueTime(g_eventQueue_ptr->getTime()), + m_DelayedCycles(0) + { } + + Message(const Message &other) + : m_time(other.m_time), + m_LastEnqueueTime(other.m_LastEnqueueTime), + m_DelayedCycles(other.m_DelayedCycles) + { } virtual ~Message() { } virtual Message* clone() const = 0; - virtual void destroy() = 0; virtual void print(std::ostream& out) const = 0; void setDelayedCycles(const int& cycles) { m_DelayedCycles = cycles; } diff --git a/src/mem/ruby/slicc_interface/NetworkMessage.hh b/src/mem/ruby/slicc_interface/NetworkMessage.hh index 41365ff9e..c92de0937 100644 --- a/src/mem/ruby/slicc_interface/NetworkMessage.hh +++ b/src/mem/ruby/slicc_interface/NetworkMessage.hh @@ -31,8 +31,7 @@ #include -#include "mem/gems_common/RefCnt.hh" -#include "mem/gems_common/RefCountable.hh" +#include "base/refcnt.hh" #include "mem/protocol/MessageSizeType.hh" #include "mem/ruby/common/Global.hh" #include "mem/ruby/common/NetDest.hh" @@ -41,16 +40,18 @@ class Address; class NetworkMessage; -typedef RefCnt NetMsgPtr; +typedef RefCountingPtr NetMsgPtr; class NetworkMessage : public Message { public: NetworkMessage() - : Message() - { - m_internal_dest_valid = false; - } + : m_internal_dest_valid(false) + { } + + NetworkMessage(const NetworkMessage &other) + : Message(other), m_internal_dest_valid(other.m_internal_dest_valid) + { } virtual ~NetworkMessage() { } -- cgit v1.2.3