diff --git a/ChangeLog b/ChangeLog index 97c3b0daa..446bb6639 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-09-30 Derek Zhou + + * Source/NSCharacterSet.m: patch to ensure lock is created as + soon as the process goes multi-threaded, therefore avoiding + a race condition causing a rare exception. + 2003-09-26 Richard Frith-Macdonald * Source/NSString.m: Fix pathExtension bug reported by Roland diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index 89db2c5ec..66ba59e76 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -3377,6 +3377,7 @@ static NSCharacterSet *tokenSet = nil; /** * Search the content of this document to locate a part whose content ID * matches the specified key. Recursively descend into other documents.
+ * Wraps the supplied key in angle brackets if they are not present.
* Return nil if no match is found, the matching GSMimeDocument otherwise. */ - (id) contentByID: (NSString*)key diff --git a/Source/NSCharacterSet.m b/Source/NSCharacterSet.m index 223e010ec..418b57f8b 100644 --- a/Source/NSCharacterSet.m +++ b/Source/NSCharacterSet.m @@ -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"; @@ -43,6 +45,18 @@ static NSLock* cache_lock = nil; @implementation NSCharacterSet ++ (void) _becomeThreaded: (NSNotification*)notification +{ + 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 +71,18 @@ static NSLock* cache_lock = nil; } 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 +99,6 @@ static NSLock* cache_lock = nil; NSString *set_path; NSBundle *bundle; - if (!cache_lock) - cache_lock = [NSLock new]; [cache_lock lock]; set = nil; /* Quiet warnings */