mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-20 18:32:04 +00:00
Simplify by assuming we will run in a multithreaded environment
This commit is contained in:
parent
99e01fe21e
commit
6eb08935ea
1 changed files with 2 additions and 44 deletions
46
GSCache.m
46
GSCache.m
|
@ -58,8 +58,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@interface GSCache (Private)
|
@interface GSCache (Private)
|
||||||
+ (void) _becomeThreaded: (NSNotification*)n;
|
|
||||||
- (void) _createLock;
|
|
||||||
- (void) _useDefaults: (NSNotification*)n;
|
- (void) _useDefaults: (NSNotification*)n;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -220,25 +218,7 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
|
||||||
if (allCaches == 0)
|
if (allCaches == 0)
|
||||||
{
|
{
|
||||||
itemOffset = class_getInstanceSize(self);
|
itemOffset = class_getInstanceSize(self);
|
||||||
allCaches
|
allCaches = NSCreateHashTable(NSNonRetainedObjectHashCallBacks, 0);
|
||||||
= NSCreateHashTable(NSNonRetainedObjectHashCallBacks, 0);
|
|
||||||
if ([NSThread isMultiThreaded] == YES)
|
|
||||||
{
|
|
||||||
[self _becomeThreaded: nil];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* If and when we become multi-threaded, the +_becomeThreaded:
|
|
||||||
* method will remove us as an observer and will create a lock
|
|
||||||
* for the table of all caches, then ask each cache to create
|
|
||||||
* its own lock.
|
|
||||||
*/
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver: self
|
|
||||||
selector: @selector(_becomeThreaded:)
|
|
||||||
name: NSWillBecomeMultiThreadedNotification
|
|
||||||
object: nil];
|
|
||||||
}
|
|
||||||
GSTickerTimeNow();
|
GSTickerTimeNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,10 +290,7 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
|
||||||
{
|
{
|
||||||
if (nil != (self = [super init]))
|
if (nil != (self = [super init]))
|
||||||
{
|
{
|
||||||
if ([NSThread isMultiThreaded] == YES)
|
my->lock = [NSRecursiveLock new];
|
||||||
{
|
|
||||||
[self _createLock];
|
|
||||||
}
|
|
||||||
my->contents = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
my->contents = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
NSObjectMapValueCallBacks, 0);
|
NSObjectMapValueCallBacks, 0);
|
||||||
[allCachesLock lock];
|
[allCachesLock lock];
|
||||||
|
@ -907,25 +884,6 @@ static void removeItem(GSCacheItem *item, GSCacheItem **first)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@implementation GSCache (Private)
|
@implementation GSCache (Private)
|
||||||
+ (void) _becomeThreaded: (NSNotification*)n
|
|
||||||
{
|
|
||||||
NSHashEnumerator e;
|
|
||||||
GSCache *c;
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver: self
|
|
||||||
name: NSWillBecomeMultiThreadedNotification object: nil];
|
|
||||||
allCachesLock = [NSRecursiveLock new];
|
|
||||||
e = NSEnumerateHashTable(allCaches);
|
|
||||||
while ((c = (GSCache*)NSNextHashEnumeratorItem(&e)) != nil)
|
|
||||||
{
|
|
||||||
[c _createLock];
|
|
||||||
}
|
|
||||||
NSEndHashTableEnumeration(&e);
|
|
||||||
}
|
|
||||||
- (void) _createLock
|
|
||||||
{
|
|
||||||
my->lock = [NSRecursiveLock new];
|
|
||||||
}
|
|
||||||
- (void) _useDefaults: (NSNotification*)n
|
- (void) _useDefaults: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
Loading…
Reference in a new issue