mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-19 10:01:20 +00:00
Remove FIFO from hash table in -release rather than -dealloc in order to avoid possible race condition where a deallocating object could be retrieved from the table.
This commit is contained in:
parent
30bb11b72a
commit
540be025c9
1 changed files with 25 additions and 7 deletions
32
GSFIFO.m
32
GSFIFO.m
|
@ -442,15 +442,33 @@ stats(NSTimeInterval ti, uint32_t max, NSTimeInterval *bounds, uint64_t *bands)
|
|||
[condition unlock];
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
{
|
||||
/* We lock the table while checking, to prevent
|
||||
* another thread from grabbing this object while we are
|
||||
* checking it.
|
||||
* If we are going to deallocate the object, we first remove
|
||||
* it from the table so that no other thread will find it
|
||||
* and try to use it while it is being deallocated.
|
||||
*/
|
||||
[classLock lock];
|
||||
if (NSDecrementExtraRefCountWasZero(self))
|
||||
{
|
||||
if (NSMapGet(allFIFOs, name) == self)
|
||||
{
|
||||
NSMapRemove(allFIFOs, name);
|
||||
}
|
||||
[classLock unlock];
|
||||
[self dealloc];
|
||||
}
|
||||
else
|
||||
{
|
||||
[classLock unlock];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[classLock lock];
|
||||
if (NSMapGet(allFIFOs, name) == self)
|
||||
{
|
||||
NSMapRemove(allFIFOs, name);
|
||||
}
|
||||
[classLock unlock];
|
||||
|
||||
[name release];
|
||||
[condition release];
|
||||
if (0 != _items)
|
||||
|
|
Loading…
Reference in a new issue