Adium

Changeset 24362

Show
Ignore:
Timestamp:
07/15/2008 01:20:15 PM (6 months ago)
Author:
sholt
Message:

If n threads containing AHHyperlinkScanners are spawned at once (as in ThreadedStressTest), it is possible that the -init code is executed by each initial threads, resulting in n-1 leaked opjects for each of our static variables. This prevents this condition from happening.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m

    r24342 r24362  
    106106- (id)init 
    107107{ 
    108         if((self = [super init])) { 
     108        static BOOL              s_allSet = NO; 
     109        static NSLock   *s_initLock = nil; 
     110        if((self = [super init]) && !s_allSet) { 
     111                if(!s_initLock) s_initLock = [[NSLock alloc] init]; 
     112                [s_initLock lock]; 
    109113                if (!skipSet) { 
    110114                        NSMutableCharacterSet *mutableSkipSet = [[NSMutableCharacterSet alloc] init]; 
     
    148152                        encKeys = [[NSArray arrayWithObjects:ENC_INDEX_KEY, ENC_CHAR_KEY, nil] retain]; 
    149153                } 
     154                s_allSet = YES; 
     155                [s_initLock unlock]; 
    150156        } 
    151157