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.
This commit is contained in:
parent
2475862747
commit
4e67ab6663
2 changed files with 11 additions and 8 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "base/trace.hh"
|
#include "base/trace.hh"
|
||||||
|
#include "cpu/thread_context.hh"
|
||||||
#include "kern/linux/printk.hh"
|
#include "kern/linux/printk.hh"
|
||||||
#include "sim/arguments.hh"
|
#include "sim/arguments.hh"
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
#define __SIM_ARGUMENTS_HH__
|
#define __SIM_ARGUMENTS_HH__
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "base/refcnt.hh"
|
|
||||||
#include "base/types.hh"
|
#include "base/types.hh"
|
||||||
#include "mem/fs_translating_port_proxy.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);
|
uint64_t getArg(uint16_t size = (uint16_t)(-1), bool fp = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
class Data : public RefCounted
|
class Data
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Data(){}
|
Data(){}
|
||||||
|
@ -60,12 +60,12 @@ class Arguments
|
||||||
char *alloc(size_t size);
|
char *alloc(size_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
RefCountingPtr<Data> data;
|
std::shared_ptr<Data> data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Arguments(ThreadContext *ctx, int n = 0)
|
Arguments(ThreadContext *ctx, int n = 0)
|
||||||
: tc(ctx), number(n), data(NULL)
|
: tc(ctx), number(n), data(new Data())
|
||||||
{ assert(number >= 0); data = new Data;}
|
{ assert(number >= 0); }
|
||||||
Arguments(const Arguments &args)
|
Arguments(const Arguments &args)
|
||||||
: tc(args.tc), number(args.number), data(args.data) {}
|
: tc(args.tc), number(args.number), data(args.data) {}
|
||||||
~Arguments() {}
|
~Arguments() {}
|
||||||
|
@ -73,9 +73,11 @@ class Arguments
|
||||||
ThreadContext *getThreadContext() const { return tc; }
|
ThreadContext *getThreadContext() const { return tc; }
|
||||||
|
|
||||||
const Arguments &operator=(const Arguments &args) {
|
const Arguments &operator=(const Arguments &args) {
|
||||||
tc = args.tc;
|
if (this != &args) {
|
||||||
number = args.number;
|
tc = args.tc;
|
||||||
data = args.data;
|
number = args.number;
|
||||||
|
data = args.data;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue