try to improve startup reliability

This commit is contained in:
Richard Frith-Macdonald 2018-04-12 18:08:53 +01:00
parent bb85bd426c
commit bc2dd4b627
3 changed files with 21 additions and 17 deletions

View file

@ -1,3 +1,10 @@
2018-04-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unicode.m:
* Source/NSCharacterSet.m:
Use pthread mutex directly to try to avoid initialising NSLock too
early on during process startup.
2018-04-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSObject.m: Don't set the name of trhe global lock until

View file

@ -35,16 +35,15 @@
#import "Foundation/NSDictionary.h"
#import "Foundation/NSError.h"
#import "Foundation/NSException.h"
#import "Foundation/NSLock.h"
#import "Foundation/NSPathUtilities.h"
#endif
#import "GNUstepBase/GSLock.h"
#import "GNUstepBase/GSMime.h"
#import "GNUstepBase/NSLock+GNUstepBase.h"
#import "GNUstepBase/Unicode.h"
#import "../GSPrivate.h"
#import "../GSPThread.h"
#include <stdio.h>
@ -138,7 +137,7 @@ internal_unicode_enc(void)
#define UNICODE_UTF32 ""
#endif
static NSLock *local_lock = nil;
static pthread_mutex_t local_lock = PTHREAD_MUTEX_INITIALIZER;
typedef unsigned char unc;
static NSStringEncoding defEnc = GSUndefinedEncoding;
@ -280,7 +279,7 @@ static void GSSetupEncodingTable(void)
{
if (encodingTable == 0)
{
[GS_INITIALIZED_LOCK(local_lock, NSLock) lock];
(void)pthread_mutex_lock(&local_lock);
if (encodingTable == 0)
{
static struct _strenc_ **encTable = 0;
@ -356,7 +355,7 @@ static void GSSetupEncodingTable(void)
}
encodingTable = encTable;
}
[local_lock unlock];
(void)pthread_mutex_unlock(&local_lock);
}
}
@ -2613,7 +2612,7 @@ GSPrivateAvailableEncodings()
if (_availableEncodings == 0)
{
GSSetupEncodingTable();
[GS_INITIALIZED_LOCK(local_lock, NSLock) lock];
(void)pthread_mutex_lock(&local_lock);
if (_availableEncodings == 0)
{
NSStringEncoding *encodings;
@ -2639,7 +2638,7 @@ GSPrivateAvailableEncodings()
encodings[pos] = 0;
_availableEncodings = encodings;
}
[local_lock unlock];
(void)pthread_mutex_unlock(&local_lock);
}
return _availableEncodings;
}
@ -2776,10 +2775,10 @@ GSPrivateDefaultCStringEncoding()
GSSetupEncodingTable();
[GS_INITIALIZED_LOCK(local_lock, NSLock) lock];
(void)pthread_mutex_lock(&local_lock);
if (defEnc != GSUndefinedEncoding)
{
[local_lock unlock];
(void)pthread_mutex_unlock(&local_lock);
return defEnc;
}
@ -2823,7 +2822,7 @@ GSPrivateDefaultCStringEncoding()
defEnc = NSISOLatin1StringEncoding;
}
[local_lock unlock];
(void)pthread_mutex_unlock(&local_lock);
}
return defEnc;
}

View file

@ -27,12 +27,11 @@
*/
#import "common.h"
#import "GNUstepBase/GSLock.h"
#import "GSPThread.h"
#import "Foundation/NSArray.h"
#import "Foundation/NSCoder.h"
#import "Foundation/NSException.h"
#import "Foundation/NSData.h"
#import "Foundation/NSLock.h"
#import "Foundation/NSDictionary.h"
#import "Foundation/NSIndexSet.h"
#import "Foundation/NSThread.h"
@ -540,7 +539,6 @@
/* A simple array for caching standard bitmap sets */
#define MAX_STANDARD_SETS 15
static NSCharacterSet *cache_set[MAX_STANDARD_SETS];
static NSLock *cache_lock = nil;
static Class abstractClass = nil;
static Class abstractMutableClass = nil;
static Class concreteClass = nil;
@ -649,8 +647,6 @@ static Class concreteMutableClass = nil;
concreteClass = [NSBitmapCharSet class];
concreteMutableClass = [NSMutableBitmapCharSet class];
#endif
cache_lock = [NSLock new];
[[NSObject leakAt: &cache_lock] release];
beenHere = YES;
}
}
@ -664,7 +660,9 @@ static Class concreteMutableClass = nil;
length: (unsigned)length
number: (int)number
{
[cache_lock lock];
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&cache_lock);
if (cache_set[number] == nil && bytes != 0)
{
NSData *bitmap;
@ -677,7 +675,7 @@ static Class concreteMutableClass = nil;
[[NSObject leakAt: &cache_set[number]] release];
RELEASE(bitmap);
}
[cache_lock unlock];
pthread_mutex_unlock(&cache_lock);
return cache_set[number];
}