mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
don't create NSLock instances during initialisation
This commit is contained in:
parent
bc2dd4b627
commit
72ad2656c8
3 changed files with 18 additions and 16 deletions
|
@ -1,7 +1,9 @@
|
|||
2018-04-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/Unicode.m:
|
||||
* Source/NSArray.m:
|
||||
* Source/NSCharacterSet.m:
|
||||
* Source/NSString.m:
|
||||
Use pthread mutex directly to try to avoid initialising NSLock too
|
||||
early on during process startup.
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
// For private method _decodeArrayOfObjectsForKey:
|
||||
#import "Foundation/NSKeyedArchiver.h"
|
||||
#import "GSPrivate.h"
|
||||
#import "GSPThread.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
#import "GSDispatch.h"
|
||||
#import "GSSorting.h"
|
||||
|
@ -85,7 +86,8 @@ static Class GSPlaceholderArrayClass;
|
|||
|
||||
static GSPlaceholderArray *defaultPlaceholderArray;
|
||||
static NSMapTable *placeholderMap;
|
||||
static NSLock *placeholderLock;
|
||||
static pthread_mutex_t placeholderLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
/**
|
||||
* A simple, low overhead, ordered container for objects. All the objects
|
||||
|
@ -105,7 +107,6 @@ static SEL rlSel;
|
|||
+ (void) atExit
|
||||
{
|
||||
DESTROY(defaultPlaceholderArray);
|
||||
DESTROY(placeholderLock);
|
||||
DESTROY(placeholderMap);
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,6 @@ static SEL rlSel;
|
|||
NSAllocateObject(GSPlaceholderArrayClass, 0, NSDefaultMallocZone());
|
||||
placeholderMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks, 0);
|
||||
placeholderLock = [NSLock new];
|
||||
[self registerAtExit];
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ static SEL rlSel;
|
|||
* locate the correct placeholder in the (lock protected)
|
||||
* table of placeholders.
|
||||
*/
|
||||
[placeholderLock lock];
|
||||
(void)pthread_mutex_lock(&placeholderLock);
|
||||
obj = (id)NSMapGet(placeholderMap, (void*)z);
|
||||
if (obj == nil)
|
||||
{
|
||||
|
@ -178,7 +178,7 @@ static SEL rlSel;
|
|||
obj = (id)NSAllocateObject(GSPlaceholderArrayClass, 0, z);
|
||||
NSMapInsert(placeholderMap, (void*)z, (void*)obj);
|
||||
}
|
||||
[placeholderLock unlock];
|
||||
(void)pthread_mutex_unlock(&placeholderLock);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#import "GNUstepBase/NSString+GNUstepBase.h"
|
||||
#import "GNUstepBase/NSMutableString+GNUstepBase.h"
|
||||
#import "GSPrivate.h"
|
||||
#import "GSPThread.h"
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
@ -149,7 +150,8 @@ static Class GSPlaceholderStringClass;
|
|||
|
||||
static GSPlaceholderString *defaultPlaceholderString;
|
||||
static NSMapTable *placeholderMap;
|
||||
static NSLock *placeholderLock;
|
||||
static pthread_mutex_t placeholderLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
static SEL cMemberSel = 0;
|
||||
static NSCharacterSet *nonBase = nil;
|
||||
|
@ -299,14 +301,14 @@ pathSeps(void)
|
|||
{
|
||||
if (rPathSeps == nil)
|
||||
{
|
||||
[placeholderLock lock];
|
||||
(void)pthread_mutex_lock(&placeholderLock);
|
||||
if (rPathSeps == nil)
|
||||
{
|
||||
rPathSeps
|
||||
= [NSCharacterSet characterSetWithCharactersInString: @"/\\"];
|
||||
rPathSeps = [NSObject leakAt: &rPathSeps];
|
||||
}
|
||||
[placeholderLock unlock];
|
||||
(void)pthread_mutex_unlock(&placeholderLock);
|
||||
}
|
||||
return rPathSeps;
|
||||
}
|
||||
|
@ -314,14 +316,14 @@ pathSeps(void)
|
|||
{
|
||||
if (uPathSeps == nil)
|
||||
{
|
||||
[placeholderLock lock];
|
||||
(void)pthread_mutex_lock(&placeholderLock);
|
||||
if (uPathSeps == nil)
|
||||
{
|
||||
uPathSeps
|
||||
= [NSCharacterSet characterSetWithCharactersInString: @"/"];
|
||||
uPathSeps = [NSObject leakAt: &uPathSeps];
|
||||
}
|
||||
[placeholderLock unlock];
|
||||
(void)pthread_mutex_unlock(&placeholderLock);
|
||||
}
|
||||
return uPathSeps;
|
||||
}
|
||||
|
@ -329,14 +331,14 @@ pathSeps(void)
|
|||
{
|
||||
if (wPathSeps == nil)
|
||||
{
|
||||
[placeholderLock lock];
|
||||
(void)pthread_mutex_lock(&placeholderLock);
|
||||
if (wPathSeps == nil)
|
||||
{
|
||||
wPathSeps
|
||||
= [NSCharacterSet characterSetWithCharactersInString: @"\\"];
|
||||
wPathSeps = [NSObject leakAt: &wPathSeps];
|
||||
}
|
||||
[placeholderLock unlock];
|
||||
(void)pthread_mutex_unlock(&placeholderLock);
|
||||
}
|
||||
return wPathSeps;
|
||||
}
|
||||
|
@ -778,7 +780,6 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
|
||||
+ (void) atExit
|
||||
{
|
||||
DESTROY(placeholderLock);
|
||||
DESTROY(placeholderMap);
|
||||
}
|
||||
|
||||
|
@ -821,7 +822,6 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
[GSPlaceholderStringClass allocWithZone: NSDefaultMallocZone()];
|
||||
placeholderMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks, 0);
|
||||
placeholderLock = [NSLock new];
|
||||
|
||||
#if defined(HAVE_REGISTER_PRINTF_SPECIFIER)
|
||||
if (register_printf_specifier ('@', handle_printf_atsign,
|
||||
|
@ -872,7 +872,7 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
* locate the correct placeholder in the (lock protected)
|
||||
* table of placeholders.
|
||||
*/
|
||||
[placeholderLock lock];
|
||||
(void)pthread_mutex_lock(&placeholderLock);
|
||||
obj = (id)NSMapGet(placeholderMap, (void*)z);
|
||||
if (obj == nil)
|
||||
{
|
||||
|
@ -883,7 +883,7 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
obj = (id)[GSPlaceholderStringClass allocWithZone: z];
|
||||
NSMapInsert(placeholderMap, (void*)z, (void*)obj);
|
||||
}
|
||||
[placeholderLock unlock];
|
||||
(void)pthread_mutex_unlock(&placeholderLock);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue