Adjust ReleaseReference() to also return the previous ref count as

AcquireReference() now does, and adjust all callers that relied on the previous
return type.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42091 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2011-06-10 22:31:33 +00:00
parent d73d70971b
commit 8c3c117201
4 changed files with 9 additions and 8 deletions
+3 -2
View File
@@ -17,9 +17,10 @@ public:
BReferenceable(); BReferenceable();
virtual ~BReferenceable(); virtual ~BReferenceable();
// acquire and release return
// the previous ref count
int32 AcquireReference(); int32 AcquireReference();
bool ReleaseReference(); int32 ReleaseReference();
// returns true after last
int32 CountReferences() const int32 CountReferences() const
{ return fReferenceCount; } { return fReferenceCount; }
@@ -2789,7 +2789,7 @@ ClientConnection::_PutVolume(ClientVolume* volume)
// decrement reference counter and remove the volume, if 0 // decrement reference counter and remove the volume, if 0
AutoLocker<VolumeMap> locker(fVolumes); AutoLocker<VolumeMap> locker(fVolumes);
bool removed = (volume->ReleaseReference() && volume->IsRemoved()); bool removed = (volume->ReleaseReference() == 1 && volume->IsRemoved());
if (removed) if (removed)
fVolumes->Remove(volume->GetID()); fVolumes->Remove(volume->GetID());
locker.Unlock(); locker.Unlock();
@@ -253,7 +253,7 @@ NetAddressResolver::~NetAddressResolver()
{ {
if (fResolver) { if (fResolver) {
_Lock(); _Lock();
if (sResolver->ReleaseReference()) { if (sResolver->ReleaseReference() == 1) {
delete sResolver; delete sResolver;
sResolver = NULL; sResolver = NULL;
} }
+4 -4
View File
@@ -41,14 +41,14 @@ BReferenceable::AcquireReference()
} }
bool int32
BReferenceable::ReleaseReference() BReferenceable::ReleaseReference()
{ {
bool unreferenced = (atomic_add(&fReferenceCount, -1) == 1); int32 previousReferenceCount = atomic_add(&fReferenceCount, -1);
TRACE("%p: release %ld\n", this, fReferenceCount); TRACE("%p: release %ld\n", this, fReferenceCount);
if (unreferenced) if (previousReferenceCount == 1)
LastReferenceReleased(); LastReferenceReleased();
return unreferenced; return previousReferenceCount;
} }