[openbeos-midi] Re: BMidiEndPoint
- From: "Marcus Overhagen" <ml@xxxxxxxxxxxx>
- To: openbeos-midi@xxxxxxxxxxxxx
- Date: Thu, 10 Oct 2002 17:44:06 CEST (+0200)
Michael Pfeiffer wrote:
> For an implementation with atomic=5Fadd see "class Object" in
> BeUtils.h in directory current/src/servers/print:
> http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/open-beos/current/src/servers/print/BeUtils.h=3Frev=3D1.2&content-type=3Dtext/vnd.viewcvs-markup
That implementation is NOT correct. You do a non-atomic read of the fRefCount
variable.
bool Release() {
atomic=5Fadd(&fRefCount, -1);
if (fRefCount =3D=3D 0) {
delete this; return true;
} else {
return false;
}
}
But atomic=5Fadd returnes the value the variable had before the addition.
You can test for that value instead
The correct way would be:
bool Release() {
if (1 =3D=3D atomic=5Fadd(&fRefCount, -1)) {
delete this; return true;
} else {
return false;
}
}
Marcus
- References:
- [openbeos-midi] Re: BMidiEndPoint
- From: Michael Pfeiffer
Other related posts:
- » [openbeos-midi] BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- » [openbeos-midi] Re: BMidiEndPoint
- [openbeos-midi] Re: BMidiEndPoint
- From: Michael Pfeiffer