more thread-safety changes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@37879 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2014-05-13 11:01:50 +00:00
parent 9feb78e6af
commit 840679cff1
2 changed files with 102 additions and 65 deletions

View file

@ -4,6 +4,7 @@
Fix tiny window in which a connection could be unlocked yet have Fix tiny window in which a connection could be unlocked yet have
the flag set to say it is in a transaction (thus potentially the flag set to say it is in a transaction (thus potentially
allowing a locking consistency error). allowing a locking consistency error).
Add locking to protect setting/changing configuration.
2014-05-08 Richard Frith-Macdonald <rfm@gnu.org> 2014-05-08 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -1155,10 +1155,10 @@ static unsigned int maxConnections = 8;
- (BOOL) connect - (BOOL) connect
{ {
if (connected == NO) if (NO == connected)
{ {
[lock lock]; [lock lock];
if (connected == NO) if (NO == connected)
{ {
NS_DURING NS_DURING
{ {
@ -1199,9 +1199,9 @@ static unsigned int maxConnections = 8;
} }
NS_HANDLER NS_HANDLER
{ {
[lock unlock];
_lastOperation = GSTickerTimeNow(); _lastOperation = GSTickerTimeNow();
_connectFails++; _connectFails++;
[lock unlock];
[localException raise]; [localException raise];
} }
NS_ENDHANDLER NS_ENDHANDLER
@ -1315,7 +1315,7 @@ static unsigned int maxConnections = 8;
- (void) disconnect - (void) disconnect
{ {
if (connected == YES) if (YES == connected)
{ {
NSNotificationCenter *nc; NSNotificationCenter *nc;
@ -1330,7 +1330,7 @@ static unsigned int maxConnections = 8;
_inTransaction = NO; _inTransaction = NO;
[lock unlock]; [lock unlock];
} }
if (connected == YES) if (YES == connected)
{ {
NS_DURING NS_DURING
{ {
@ -1772,6 +1772,9 @@ static unsigned int maxConnections = 8;
} }
- (void) setDatabase: (NSString*)s - (void) setDatabase: (NSString*)s
{
[lock lock];
NS_DURING
{ {
if ([s isEqual: _database] == NO) if ([s isEqual: _database] == NO)
{ {
@ -1784,35 +1787,40 @@ static unsigned int maxConnections = 8;
_database = s; _database = s;
} }
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
}
- (void) setName: (NSString*)s - (void) setName: (NSString*)s
{
[lock lock];
NS_DURING
{ {
if ([s isEqual: _name] == NO) if ([s isEqual: _name] == NO)
{ {
[lock lock];
if ([s isEqual: _name] == YES)
{
[lock unlock];
return;
}
[clientsMapLock lock]; [clientsMapLock lock];
if (NSMapGet(clientsMap, s) != 0) if (NSMapGet(clientsMap, s) != 0)
{ {
[lock unlock];
[clientsMapLock unlock]; [clientsMapLock unlock];
[lock unlock];
if ([self debugging] > 0) if ([self debugging] > 0)
{ {
[self debug: @"Error attempt to re-use client name %@", s]; [self debug: @"Error attempt to re-use client name %@", s];
} }
return; NS_VOIDRETURN;
} }
if (connected == YES) if (connected == YES)
{ {
[self disconnect]; [self disconnect];
} }
[self retain];
if (_name != nil) if (_name != nil)
{ {
[[self retain] autorelease];
NSMapRemove(clientsMap, (void*)_name); NSMapRemove(clientsMap, (void*)_name);
} }
s = [s copy]; s = [s copy];
@ -1822,12 +1830,21 @@ static unsigned int maxConnections = 8;
_client = [[[NSProcessInfo processInfo] globallyUniqueString] retain]; _client = [[[NSProcessInfo processInfo] globallyUniqueString] retain];
NSMapInsert(clientsMap, (void*)_name, (void*)self); NSMapInsert(clientsMap, (void*)_name, (void*)self);
[clientsMapLock unlock]; [clientsMapLock unlock];
[lock unlock];
[self release];
} }
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
}
- (void) setPassword: (NSString*)s - (void) setPassword: (NSString*)s
{
[lock lock];
NS_DURING
{ {
if ([s isEqual: _password] == NO) if ([s isEqual: _password] == NO)
{ {
@ -1840,6 +1857,14 @@ static unsigned int maxConnections = 8;
_password = s; _password = s;
} }
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
}
- (void) setShouldTrim: (BOOL)aFlag - (void) setShouldTrim: (BOOL)aFlag
{ {
@ -1847,6 +1872,9 @@ static unsigned int maxConnections = 8;
} }
- (void) setUser: (NSString*)s - (void) setUser: (NSString*)s
{
[lock lock];
NS_DURING
{ {
if ([s isEqual: _client] == NO) if ([s isEqual: _client] == NO)
{ {
@ -1859,6 +1887,14 @@ static unsigned int maxConnections = 8;
_user = s; _user = s;
} }
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
}
- (NSInteger) simpleExecute: (NSArray*)info - (NSInteger) simpleExecute: (NSArray*)info
{ {
@ -2778,7 +2814,7 @@ static unsigned int maxConnections = 8;
GSCache *c; GSCache *c;
[lock lock]; [lock lock];
if (_cache == nil) if (nil == _cache)
{ {
_cache = [GSCache new]; _cache = [GSCache new];
if (_cacheThread != nil) if (_cacheThread != nil)