small thread safety fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@23450 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-09-10 13:54:58 +00:00
parent 5e0d538fc2
commit 6fe5ff5763

View file

@ -204,6 +204,8 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
- (void) dealloc
{
[GSCacheLock lock];
NSHashRemove(GSCacheInstances, (void*)self);
[GSCacheLock unlock];
if (my->contents != 0)
{
[self shrinkObjects: 0 andSize: 0];
@ -211,8 +213,6 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
}
RELEASE(my->exclude);
RELEASE(my->name);
NSHashRemove(GSCacheInstances, (void*)self);
[GSCacheLock unlock];
[super dealloc];
}
@ -345,6 +345,28 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
}
}
- (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.
*/
[GSCacheLock lock];
if (NSDecrementExtraRefCountWasZero(self))
{
NSHashRemove(GSCacheInstances, (void*)self);
[GSCacheLock unlock];
[self dealloc];
}
else
{
[GSCacheLock unlock];
}
}
- (void) setDelegate: (id)anObject
{
my->delegate = anObject;