mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
more threading fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23448 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bdf6b69bce
commit
3f65c97d1a
3 changed files with 39 additions and 3 deletions
|
@ -4,7 +4,9 @@
|
||||||
Roland Schwingel reported that it caught legitimate files on windows.
|
Roland Schwingel reported that it caught legitimate files on windows.
|
||||||
* Source/NSMessagePort.m:
|
* Source/NSMessagePort.m:
|
||||||
* Source/NSSocketPort.m:
|
* Source/NSSocketPort.m:
|
||||||
Protect -release with lock and remove port from gloibal table within
|
* Source/NSIndexPath.m:
|
||||||
|
* Source/NSBundle.m:
|
||||||
|
Protect -release with lock and remove object from global table within
|
||||||
protected region, to avoid possible double deallocation in a
|
protected region, to avoid possible double deallocation in a
|
||||||
multithreaded process.
|
multithreaded process.
|
||||||
|
|
||||||
|
|
|
@ -1428,6 +1428,19 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) release
|
||||||
|
{
|
||||||
|
/* We lock during release so that other threads can't grab the
|
||||||
|
* object between us checking the reference count and deallocating.
|
||||||
|
*/
|
||||||
|
[load_lock lock];
|
||||||
|
if (NSDecrementExtraRefCountWasZero(self))
|
||||||
|
{
|
||||||
|
[self dealloc];
|
||||||
|
}
|
||||||
|
[load_lock unlock];
|
||||||
|
}
|
||||||
|
|
||||||
/* This method is the backbone of the resource searching for NSBundle. It
|
/* This method is the backbone of the resource searching for NSBundle. It
|
||||||
constructs an array of paths, where each path is a possible location
|
constructs an array of paths, where each path is a possible location
|
||||||
for a resource in the bundle. The current algorithm for searching goes:
|
for a resource in the bundle. The current algorithm for searching goes:
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <Foundation/NSKeyedArchiver.h>
|
#include <Foundation/NSKeyedArchiver.h>
|
||||||
#include <Foundation/NSLock.h>
|
#include <Foundation/NSLock.h>
|
||||||
#include <Foundation/NSZone.h>
|
#include <Foundation/NSZone.h>
|
||||||
|
#include "GNUstepBase/GSLock.h"
|
||||||
|
|
||||||
static NSLock *lock = nil;
|
static NSLock *lock = nil;
|
||||||
static NSHashTable *shared = 0;
|
static NSHashTable *shared = 0;
|
||||||
|
@ -72,7 +73,7 @@ static NSIndexPath *dummy = nil;
|
||||||
dummy = (NSIndexPath*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
dummy = (NSIndexPath*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||||
shared = NSCreateHashTable(NSNonRetainedObjectHashCallBacks, 1024);
|
shared = NSCreateHashTable(NSNonRetainedObjectHashCallBacks, 1024);
|
||||||
NSHashInsert(shared, empty);
|
NSHashInsert(shared, empty);
|
||||||
lock = [NSLock new];
|
lock = [GSLazyRecursiveLock new];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ static NSIndexPath *dummy = nil;
|
||||||
GSNOSUPERDEALLOC;
|
GSNOSUPERDEALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*)description
|
- (NSString*) description
|
||||||
{
|
{
|
||||||
NSMutableString *m = [[super description] mutableCopy];
|
NSMutableString *m = [[super description] mutableCopy];
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -425,5 +426,25 @@ static NSIndexPath *dummy = nil;
|
||||||
return _length;
|
return _length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) release
|
||||||
|
{
|
||||||
|
if (self != empty)
|
||||||
|
{
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
[lock lock];
|
||||||
|
if (NSDecrementExtraRefCountWasZero(self))
|
||||||
|
{
|
||||||
|
[self dealloc];
|
||||||
|
}
|
||||||
|
[lock unlock];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue