mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-11 00:30:49 +00:00
Better lock protection of shared instance and cleanup at exit
This commit is contained in:
parent
ce9699d5c5
commit
9fadc19f8c
1 changed files with 23 additions and 4 deletions
|
@ -661,7 +661,9 @@ newLanguages(NSArray *oldNames)
|
||||||
|
|
||||||
+ (void) atExit
|
+ (void) atExit
|
||||||
{
|
{
|
||||||
|
[classLock lock];
|
||||||
DESTROY(sharedDefaults);
|
DESTROY(sharedDefaults);
|
||||||
|
[classLock unlock];
|
||||||
DESTROY(bundleIdentifier);
|
DESTROY(bundleIdentifier);
|
||||||
DESTROY(processName);
|
DESTROY(processName);
|
||||||
DESTROY(argumentsDictionary);
|
DESTROY(argumentsDictionary);
|
||||||
|
@ -842,11 +844,13 @@ newLanguages(NSArray *oldNames)
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
if (nil != regDefs)
|
if (nil != regDefs)
|
||||||
{
|
{
|
||||||
[self standardUserDefaults];
|
NSUserDefaults *defs = [self standardUserDefaults];
|
||||||
if (sharedDefaults != nil)
|
|
||||||
|
if (defs != nil)
|
||||||
{
|
{
|
||||||
[sharedDefaults->_tempDomains setObject: regDefs
|
[defs->_lock lock];
|
||||||
forKey: NSRegistrationDomain];
|
[defs->_tempDomains setObject: regDefs forKey: NSRegistrationDomain];
|
||||||
|
[defs->_lock unlock];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1353,6 +1357,21 @@ newLanguages(NSArray *oldNames)
|
||||||
return [self initWithContentsOfFile: path];
|
return [self initWithContentsOfFile: path];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This code ensures that, if the shared instance is about to be deallocated
|
||||||
|
* we clear the sharedDefaults variable first so that no other thread can
|
||||||
|
* grab a reference to the deallocated instance.
|
||||||
|
*/
|
||||||
|
- (void) release
|
||||||
|
{
|
||||||
|
[classLock lock];
|
||||||
|
if (self == sharedDefaults && [self retainCount] < 2)
|
||||||
|
{
|
||||||
|
sharedDefaults = nil;
|
||||||
|
}
|
||||||
|
[classLock unlock];
|
||||||
|
[super release];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||||
|
|
Loading…
Reference in a new issue