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:
parent
905bdfe41c
commit
a744b32df3
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user