changeset 8c1b836edc92 in /z/repo/gem5 details: http://repo.gem5.org/gem5?cmd=changeset;node=8c1b836edc92 description: dev: Use shared_ptr for Arguments::Data
This patch takes a first few steps in transitioning from the ad-hoc RefCountingPtr to the c++11 shared_ptr. There are no changes in behaviour, and the code modifications are mainly introducing the use of make_shared. Note that the class could use unique_ptr rather than shared_ptr, was it not for the postfix increment and decrement operators. diffstat: src/kern/linux/printk.cc | 1 + src/sim/arguments.hh | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diffs (64 lines): diff -r dcf27c8220ac -r 8c1b836edc92 src/kern/linux/printk.cc --- a/src/kern/linux/printk.cc Thu Oct 16 05:49:44 2014 -0400 +++ b/src/kern/linux/printk.cc Thu Oct 16 05:49:45 2014 -0400 @@ -34,6 +34,7 @@ #include <algorithm> #include "base/trace.hh" +#include "cpu/thread_context.hh" #include "kern/linux/printk.hh" #include "sim/arguments.hh" diff -r dcf27c8220ac -r 8c1b836edc92 src/sim/arguments.hh --- a/src/sim/arguments.hh Thu Oct 16 05:49:44 2014 -0400 +++ b/src/sim/arguments.hh Thu Oct 16 05:49:45 2014 -0400 @@ -32,8 +32,8 @@ #define __SIM_ARGUMENTS_HH__ #include <cassert> +#include <memory> -#include "base/refcnt.hh" #include "base/types.hh" #include "mem/fs_translating_port_proxy.hh" @@ -47,7 +47,7 @@ uint64_t getArg(uint16_t size = (uint16_t)(-1), bool fp = false); protected: - class Data : public RefCounted + class Data { public: Data(){} @@ -60,12 +60,12 @@ char *alloc(size_t size); }; - RefCountingPtr<Data> data; + std::shared_ptr<Data> data; public: Arguments(ThreadContext *ctx, int n = 0) - : tc(ctx), number(n), data(NULL) - { assert(number >= 0); data = new Data;} + : tc(ctx), number(n), data(new Data()) + { assert(number >= 0); } Arguments(const Arguments &args) : tc(args.tc), number(args.number), data(args.data) {} ~Arguments() {} @@ -73,9 +73,11 @@ ThreadContext *getThreadContext() const { return tc; } const Arguments &operator=(const Arguments &args) { - tc = args.tc; - number = args.number; - data = args.data; + if (this != &args) { + tc = args.tc; + number = args.number; + data = args.data; + } return *this; } _______________________________________________ gem5-dev mailing list gem5-dev@gem5.org http://m5sim.org/mailman/listinfo/gem5-dev