Commit 02476694 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron

AutoObj: change clean-up semantics:

* Using "delete this" in shared data to remove that responsibility from
  the object referencing it
parent 375fe3a0
......@@ -67,10 +67,10 @@ public:
{ d = new AutoLockData(mutex, state); }
AutoLock(const AutoLock& o)
{ d = o.getData(); }
{ d = o.d->get(); }
~AutoLock()
{ putData(); }
{ d->put(); }
void lock()
{ d->lock(); }
......@@ -92,8 +92,8 @@ public:
AutoLock& operator =(const AutoLock& o)
{
AutoLockData *od = o.getData(); // protects against "a = a"
putData();
AutoLockData *od = o.d->get(); // protects against "a = a"
d->put();
d = od;
return *this;
}
......@@ -125,9 +125,10 @@ private:
return this;
}
bool put()
void put()
{
return c.put();
if (c.put())
delete this;
}
void lock()
......@@ -169,16 +170,6 @@ private:
bool ul_at_end;
};
AutoLockData *getData() const
{ return d->get(); }
void putData()
{
if (d->put())
delete d;
d = NULL;
}
AutoLockData *d;
};
......@@ -281,9 +272,7 @@ public:
T *forget()
{
T *ptr = getPtr();
if (d)
d->forget();
T *ptr = d ? d->forget() : NULL;
setPtr(NULL);
return ptr;
}
......@@ -307,9 +296,10 @@ private:
return this;
}
bool put()
void put()
{
return c.put();
if (c.put())
delete this;
}
void free()
......@@ -347,8 +337,8 @@ private:
void putData()
{
if (d && d->put())
delete d;
if (d)
d->put();
}
AutoPtrData *d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment