improve thread safety when using zombies

This commit is contained in:
Richard Frith-Macdonald 2019-02-11 09:09:20 +00:00
parent cb2998641e
commit 921f7521ff
2 changed files with 33 additions and 4 deletions

View file

@ -1,3 +1,10 @@
2019-02-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSObject.m: Improve thread safety with NSZombie particularly
on startup/shutdown; be more careful about locking access to the
zombieMap and also ensuring we don't raise an exception inside the
locked sections (by passing a nil map to the functions).
2019-01-06 Armando Pesenti Gritti <armando.pesentigritti@theengagehub.com>
* Headers/GNUstepBase/GSTLS.h: Header moved to provide public

View file

@ -145,7 +145,10 @@ static void GSMakeZombie(NSObject *o, Class c)
if (0 != zombieMap)
{
pthread_mutex_lock(&allocationLock);
NSMapInsert(zombieMap, (void*)o, (void*)c);
if (0 != zombieMap)
{
NSMapInsert(zombieMap, (void*)o, (void*)c);
}
pthread_mutex_unlock(&allocationLock);
}
}
@ -158,7 +161,10 @@ static void GSLogZombie(id o, SEL sel)
if (0 != zombieMap)
{
pthread_mutex_lock(&allocationLock);
c = NSMapGet(zombieMap, (void*)o);
if (0 != zombieMap)
{
c = NSMapGet(zombieMap, (void*)o);
}
pthread_mutex_unlock(&allocationLock);
}
if (c == 0)
@ -834,7 +840,10 @@ NSDeallocateObject(id anObject)
if (0 != zombieMap)
{
pthread_mutex_lock(&allocationLock);
NSMapInsert(zombieMap, (void*)anObject, (void*)aClass);
if (0 != zombieMap)
{
NSMapInsert(zombieMap, (void*)anObject, (void*)aClass);
}
pthread_mutex_unlock(&allocationLock);
}
if (NSDeallocateZombies == YES)
@ -1108,7 +1117,9 @@ static id gs_weak_load(id obj)
+ (void) _atExit
{
pthread_mutex_lock(&allocationLock);
DESTROY(zombieMap);
pthread_mutex_unlock(&allocationLock);
}
/**
@ -2483,7 +2494,18 @@ static id gs_weak_load(id obj)
}
- (Class) originalClass
{
return zombieMap ? NSMapGet(zombieMap, (void*)self) : Nil;
Class c = Nil;
if (0 != zombieMap)
{
pthread_mutex_lock(&allocationLock);
if (0 != zombieMap)
{
c = NSMapGet(zombieMap, (void*)self);
}
pthread_mutex_unlock(&allocationLock);
}
return c;
}
- (void) forwardInvocation: (NSInvocation*)anInvocation
{