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
{ {
@ -1773,72 +1773,97 @@ static unsigned int maxConnections = 8;
- (void) setDatabase: (NSString*)s - (void) setDatabase: (NSString*)s
{ {
if ([s isEqual: _database] == NO) [lock lock];
NS_DURING
{ {
if (connected == YES) if ([s isEqual: _database] == NO)
{ {
[self disconnect]; if (connected == YES)
} {
s = [s copy]; [self disconnect];
[_database release]; }
_database = s; s = [s copy];
[_database release];
_database = s;
}
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
} }
- (void) setName: (NSString*)s - (void) setName: (NSString*)s
{ {
if ([s isEqual: _name] == NO) [lock lock];
NS_DURING
{ {
[lock lock]; if ([s isEqual: _name] == NO)
if ([s isEqual: _name] == YES) {
{ [clientsMapLock lock];
[lock unlock]; if (NSMapGet(clientsMap, s) != 0)
return; {
} [clientsMapLock unlock];
[clientsMapLock lock]; [lock unlock];
if (NSMapGet(clientsMap, s) != 0) if ([self debugging] > 0)
{ {
[lock unlock]; [self debug: @"Error attempt to re-use client name %@", s];
[clientsMapLock unlock]; }
if ([self debugging] > 0) NS_VOIDRETURN;
{ }
[self debug: @"Error attempt to re-use client name %@", s]; if (connected == YES)
} {
return; [self disconnect];
} }
if (connected == YES) if (_name != nil)
{ {
[self disconnect]; [[self retain] autorelease];
} NSMapRemove(clientsMap, (void*)_name);
[self retain]; }
if (_name != nil) s = [s copy];
{ [_name release];
NSMapRemove(clientsMap, (void*)_name); _name = s;
[_client release];
_client = [[[NSProcessInfo processInfo] globallyUniqueString] retain];
NSMapInsert(clientsMap, (void*)_name, (void*)self);
[clientsMapLock unlock];
} }
s = [s copy];
[_name release];
_name = s;
[_client release];
_client = [[[NSProcessInfo processInfo] globallyUniqueString] retain];
NSMapInsert(clientsMap, (void*)_name, (void*)self);
[clientsMapLock unlock];
[lock unlock];
[self release];
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
} }
- (void) setPassword: (NSString*)s - (void) setPassword: (NSString*)s
{ {
if ([s isEqual: _password] == NO) [lock lock];
NS_DURING
{ {
if (connected == YES) if ([s isEqual: _password] == NO)
{ {
[self disconnect]; if (connected == YES)
} {
s = [s copy]; [self disconnect];
[_password release]; }
_password = s; s = [s copy];
[_password release];
_password = s;
}
} }
NS_HANDLER
{
[lock unlock];
[localException raise];
}
NS_ENDHANDLER
[lock unlock];
} }
- (void) setShouldTrim: (BOOL)aFlag - (void) setShouldTrim: (BOOL)aFlag
@ -1848,16 +1873,27 @@ static unsigned int maxConnections = 8;
- (void) setUser: (NSString*)s - (void) setUser: (NSString*)s
{ {
if ([s isEqual: _client] == NO) [lock lock];
NS_DURING
{ {
if (connected == YES) if ([s isEqual: _client] == NO)
{ {
[self disconnect]; if (connected == YES)
} {
s = [s copy]; [self disconnect];
[_user release]; }
_user = s; s = [s copy];
[_user release];
_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)