This patch make NSCharacterSet alloc a lock only when the processs is going
multi-threaded, just like most other class in Foundation.
Derek
--- gnustep-base-1.8.0/Source/NSCharacterSet.m 2003-06-06 18:24:40.000000000 -0700
+++ gnustep-base-1.8.0_new/Source/NSCharacterSet.m 2003-09-29 16:06:53.000000000 -0700
@@ -33,6 +33,8 @@
#include "Foundation/NSLock.h"
#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSDictionary.h"
+#include "Foundation/NSThread.h"
+#include "Foundation/NSNotification.h"
static NSString* NSCharacterSet_PATH = @"NSCharacterSets";
@@ -40,9 +42,26 @@
#define MAX_STANDARD_SETS 15
static NSCharacterSet* cache_set[MAX_STANDARD_SETS];
static NSLock* cache_lock = nil;
+static BOOL multi_threaded = NO;
@implementation NSCharacterSet
++ (void) _becomeThreaded: (NSNotification*)notification
+{
+ if (multi_threaded == NO)
+ {
+ multi_threaded = YES;
+ if (cache_lock == nil)
+ {
+ cache_lock = [NSLock new];
+ }
+ }
+ [[NSNotificationCenter defaultCenter]
+ removeObserver: self
+ name: NSWillBecomeMultiThreadedNotification
+ object: nil];
+}
+
+ (void) initialize
{
static BOOL one_time = NO;
@@ -57,6 +76,18 @@
}
one_time = YES;
}
+ if ([NSThread isMultiThreaded])
+ {
+ [self _becomeThreaded: nil];
+ }
+ else
+ {
+ [[NSNotificationCenter defaultCenter]
+ addObserver: self
+ selector: @selector(_becomeThreaded:)
+ name: NSWillBecomeMultiThreadedNotification
+ object: nil];
+ }
}
/* Provide a default object for allocation */
@@ -73,8 +104,6 @@
NSString *set_path;
NSBundle *bundle;
- if (!cache_lock)
- cache_lock = [NSLock new];
[cache_lock lock];
set = nil; /* Quiet warnings */
_______________________________________________
Bug-gnustep mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gnustep