diff options
author | Andreas Hansson <andreas.hansson@arm.com> | 2014-10-16 05:49:45 -0400 |
---|---|---|
committer | Andreas Hansson <andreas.hansson@arm.com> | 2014-10-16 05:49:45 -0400 |
commit | 4e67ab6663f8f4960a1078546906746877f87e1a (patch) | |
tree | cf219b3ca01604fe22169c28af237f0fe373a106 /src | |
parent | 247586274724ea9f2a22a87747c9e074870d16a8 (diff) | |
download | gem5-4e67ab6663f8f4960a1078546906746877f87e1a.tar.xz |
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 (limited to 'src')
-rw-r--r-- | src/kern/linux/printk.cc | 1 | ||||
-rw-r--r-- | src/sim/arguments.hh | 18 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/kern/linux/printk.cc b/src/kern/linux/printk.cc index 7a4c551ce..c2cf60964 100644 --- a/src/kern/linux/printk.cc +++ b/src/kern/linux/printk.cc @@ -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 --git a/src/sim/arguments.hh b/src/sim/arguments.hh index 58a43852c..165880095 100644 --- a/src/sim/arguments.hh +++ b/src/sim/arguments.hh @@ -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 @@ class Arguments 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 @@ class Arguments 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 @@ class Arguments 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; } |