More simplification by using lazy locking

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18559 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-02-08 09:42:38 +00:00
parent cf6e91f1fd
commit d04dcc7fb8
9 changed files with 37 additions and 350 deletions

View file

@ -25,6 +25,7 @@
*/
#include "config.h"
#include "GNUstepBase/GSLock.h"
#include "Foundation/NSSet.h"
#include "Foundation/NSCoder.h"
#include "Foundation/NSArray.h"
@ -47,10 +48,6 @@ static IMP lockImp = 0;
static IMP unlockImp = 0;
static BOOL uniquing = NO;
@interface NSCountedSet (GSThreading)
+ (void) _becomeThreaded: (id)notification;
@end
/**
* <p>
* The NSCountedSet class is used to maintain a set of objects where
@ -73,18 +70,9 @@ static Class NSCountedSet_concrete_class;
{
NSCountedSet_abstract_class = self;
NSCountedSet_concrete_class = [GSCountedSet class];
if ([NSThread isMultiThreaded])
{
[self _becomeThreaded: nil];
}
else
{
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_becomeThreaded:)
name: NSWillBecomeMultiThreadedNotification
object: nil];
}
uniqueLock = [GSLazyLock new];
lockImp = [uniqueLock methodForSelector: @selector(lock)];
unlockImp = [uniqueLock methodForSelector: @selector(unlock)];
}
}
@ -299,18 +287,6 @@ static Class NSCountedSet_concrete_class;
}
@end
@implementation NSCountedSet (GSThreading)
/*
* If we are multi-threaded, we must guard access to the uniquing set.
*/
+ (void) _becomeThreaded: (id)notification
{
uniqueLock = [NSLock new];
lockImp = [uniqueLock methodForSelector: @selector(lock)];
unlockImp = [uniqueLock methodForSelector: @selector(unlock)];
}
@end
/**
* This function purges the global NSCountedSet object used for
* uniquing. It handles locking as necessary. It can be used to