summaryrefslogtreecommitdiff
path: root/base/refcnt.hh
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2004-10-23 16:18:44 -0400
committerNathan Binkert <binkertn@umich.edu>2004-10-23 16:18:44 -0400
commita7fd7729ab908d8f93b9bbd290d43f1f21695e3d (patch)
treeba4270879f2e8635f21c6c751c0ffc7bcbe4c6f9 /base/refcnt.hh
parent833c5b5ef49b4b0ff6c1736b71b6149feee50cb5 (diff)
downloadgem5-a7fd7729ab908d8f93b9bbd290d43f1f21695e3d.tar.xz
flesh out the TCP/IP/Ethernet support
base/refcnt.hh: reorganize the RefCountingPtr a little bit to make it easier to derive from dev/etherpkt.hh: this doesn't belong here. use the inet.hh stuff dev/ns_gige.cc: dev/ns_gige.hh: use newer features in the tcp/ip/ethernet stuff --HG-- extra : convert_revision : 32c1953c95655c1f4c70e0d8adedfd94beead624
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; }