mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-23 20:01:15 +00:00
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:
parent
5e0d538fc2
commit
6fe5ff5763
1 changed files with 24 additions and 2 deletions
26
GSCache.m
26
GSCache.m
|
@ -204,6 +204,8 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[GSCacheLock lock];
|
[GSCacheLock lock];
|
||||||
|
NSHashRemove(GSCacheInstances, (void*)self);
|
||||||
|
[GSCacheLock unlock];
|
||||||
if (my->contents != 0)
|
if (my->contents != 0)
|
||||||
{
|
{
|
||||||
[self shrinkObjects: 0 andSize: 0];
|
[self shrinkObjects: 0 andSize: 0];
|
||||||
|
@ -211,8 +213,6 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
|
||||||
}
|
}
|
||||||
RELEASE(my->exclude);
|
RELEASE(my->exclude);
|
||||||
RELEASE(my->name);
|
RELEASE(my->name);
|
||||||
NSHashRemove(GSCacheInstances, (void*)self);
|
|
||||||
[GSCacheLock unlock];
|
|
||||||
[super dealloc];
|
[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
|
- (void) setDelegate: (id)anObject
|
||||||
{
|
{
|
||||||
my->delegate = anObject;
|
my->delegate = anObject;
|
||||||
|
|
Loading…
Reference in a new issue