Fixed race condition in Release(), supplied by Marcus Overhangen.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1529 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2002-10-15 15:53:49 +00:00
parent 905bdfe41c
commit a744b32df3
1 changed files with 8 additions and 9 deletions

View File

@ -57,19 +57,18 @@ public:
// dtor should be private, but ie. ObjectList requires a public dtor!
virtual ~Object() { };
// thread-safe as long as thread that calls acquire has already
// thread-safe as long as thread that calls Acquire has already
// a reference to the object
void Acquire() {
void Acquire() {
atomic_add(&fRefCount, 1);
}
bool Release() {
atomic_add(&fRefCount, -1);
if (fRefCount == 0) {
delete this; return true;
} else {
return false;
}
bool Release() {
if (atomic_add(&fRefCount, -1) == 1) {
delete this; return true;
} else {
return false;
}
}
};