changeset 0433264984ce in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=0433264984ce
description:
base: Use shared_ptr for stat Node
This patch transitions the stat Node 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".
diffstat:
src/base/statistics.hh | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diffs (110 lines):
diff -r 2c6a72e919f6 -r 0433264984ce src/base/statistics.hh
--- a/src/base/statistics.hh Thu Oct 16 05:49:47 2014 -0400
+++ b/src/base/statistics.hh Thu Oct 16 05:49:48 2014 -0400
@@ -57,6 +57,7 @@
#include <iosfwd>
#include <list>
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -66,7 +67,6 @@
#include "base/cast.hh"
#include "base/cprintf.hh"
#include "base/intmath.hh"
-#include "base/refcnt.hh"
#include "base/str.hh"
#include "base/types.hh"
@@ -2050,7 +2050,7 @@
* Base class for formula statistic node. These nodes are used to build a tree
* that represents the formula.
*/
-class Node : public RefCounted
+class Node
{
public:
/**
@@ -2075,8 +2075,8 @@
virtual std::string str() const = 0;
};
-/** Reference counting pointer to a function Node. */
-typedef RefCountingPtr<Node> NodePtr;
+/** Shared pointer to a function Node. */
+typedef std::shared_ptr<Node> NodePtr;
class ScalarStatNode : public Node
{
@@ -2989,7 +2989,9 @@
* Copy the given pointer to this class.
* @param n A pointer to a Node object to copy.
*/
- Temp(NodePtr n) : node(n) { }
+ Temp(const NodePtr &n) : node(n) { }
+
+ Temp(NodePtr &&n) : node(std::move(n)) { }
/**
* Return the node pointer.
@@ -3155,51 +3157,51 @@
inline Temp
operator+(Temp l, Temp r)
{
- return NodePtr(new BinaryNode<std::plus<Result> >(l, r));
+ return Temp(std::make_shared<BinaryNode<std::plus<Result> > >(l, r));
}
inline Temp
operator-(Temp l, Temp r)
{
- return NodePtr(new BinaryNode<std::minus<Result> >(l, r));
+ return Temp(std::make_shared<BinaryNode<std::minus<Result> > >(l, r));
}
inline Temp
operator*(Temp l, Temp r)
{
- return NodePtr(new BinaryNode<std::multiplies<Result> >(l, r));
+ return Temp(std::make_shared<BinaryNode<std::multiplies<Result> > >(l, r));
}
inline Temp
operator/(Temp l, Temp r)
{
- return NodePtr(new BinaryNode<std::divides<Result> >(l, r));
+ return Temp(std::make_shared<BinaryNode<std::divides<Result> > >(l, r));
}
inline Temp
operator-(Temp l)
{
- return NodePtr(new UnaryNode<std::negate<Result> >(l));
+ return Temp(std::make_shared<UnaryNode<std::negate<Result> > >(l));
}
template <typename T>
inline Temp
constant(T val)
{
- return NodePtr(new ConstNode<T>(val));
+ return Temp(std::make_shared<ConstNode<T> >(val));
}
template <typename T>
inline Temp
constantVector(T val)
{
- return NodePtr(new ConstVectorNode<T>(val));
+ return Temp(std::make_shared<ConstVectorNode<T> >(val));
}
inline Temp
sum(Temp val)
{
- return NodePtr(new SumNode<std::plus<Result> >(val));
+ return Temp(std::make_shared<SumNode<std::plus<Result> > >(val));
}
/** Dump all statistics data to the registered outputs */
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev