summaryrefslogtreecommitdiff
path: root/base/refcnt.hh
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2004-10-23 16:18:53 -0400
committerNathan Binkert <binkertn@umich.edu>2004-10-23 16:18:53 -0400
commit6ac0d27b7dc130397b6ba9b11e593706c2f669fe (patch)
treeba4270879f2e8635f21c6c751c0ffc7bcbe4c6f9 /base/refcnt.hh
parentef145b2827b72453c22384a5955312343017ded1 (diff)
parenta7fd7729ab908d8f93b9bbd290d43f1f21695e3d (diff)
downloadgem5-6ac0d27b7dc130397b6ba9b11e593706c2f669fe.tar.xz
Merge zizzer.eecs.umich.edu:/bk/m5
into ziff.eecs.umich.edu:/z/binkertn/research/m5/latest --HG-- extra : convert_revision : aaf81b1c1283229de21e0ef7e9916a4464f72fa3
Diffstat (limited to 'base/refcnt.hh')
-rw-r--r--base/refcnt.hh33
1 files changed, 16 insertions, 17 deletions
diff --git a/base/refcnt.hh b/base/refcnt.hh
index 251dc905b..00ba8fa4a 100644
--- a/base/refcnt.hh
+++ b/base/refcnt.hh
@@ -51,15 +51,26 @@ class RefCountingPtr
protected:
T *data;
- void copy(T *d) {
+ void copy(T *d)
+ {
data = d;
if (data)
data->incref();
}
- void del() {
+ void del()
+ {
if (data)
data->decref();
}
+ void set(T *d)
+ {
+ if (data == d)
+ return;
+
+ del();
+ copy(d);
+ }
+
public:
RefCountingPtr() : data(NULL) {}
@@ -75,21 +86,9 @@ class RefCountingPtr
const T &operator*() const { return *data; }
const T *get() const { return data; }
- RefCountingPtr &operator=(T *p) {
- if (data != p) {
- del();
- copy(p);
- }
- return *this;
- }
-
- RefCountingPtr &operator=(const RefCountingPtr &r) {
- if (data != r.data) {
- del();
- copy(r.data);
- }
- return *this;
- }
+ RefCountingPtr &operator=(T *p) { set(p); return *this; }
+ RefCountingPtr &operator=(const RefCountingPtr &r)
+ { return operator=(r.data); }
bool operator!() const { return data == 0; }
operator bool() const { return data != 0; }