locking cleanups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@33842 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-09-16 07:25:33 +00:00
parent 10a8ac3164
commit 837ddf035f
3 changed files with 40 additions and 21 deletions

View file

@ -1,3 +1,8 @@
2011-04-01 Richard Frith-Macdonald <rfm@gnu.org>
* SQLClient.m: Cleanup locking on -begin/-commit/-rollback
* Version 1.5.2: bump version number
2011-04-01 Richard Frith-Macdonald <rfm@gnu.org> 2011-04-01 Richard Frith-Macdonald <rfm@gnu.org>
* Version 1.5.1: bump version number * Version 1.5.1: bump version number

View file

@ -21,7 +21,7 @@ include $(GNUSTEP_MAKEFILES)/common.make
-include config.make -include config.make
PACKAGE_NAME = SQLClient PACKAGE_NAME = SQLClient
PACKAGE_VERSION = 1.5.1 PACKAGE_VERSION = 1.5.2
CVS_MODULE_NAME = gnustep/dev-libs/SQLClient CVS_MODULE_NAME = gnustep/dev-libs/SQLClient
CVS_TAG_NAME = SQLClient CVS_TAG_NAME = SQLClient
SVN_BASE_URL=svn+ssh://svn.gna.org/svn/gnustep/libs SVN_BASE_URL=svn+ssh://svn.gna.org/svn/gnustep/libs

View file

@ -1074,6 +1074,10 @@ static unsigned int maxConnections = 8;
NS_DURING NS_DURING
{ {
[self simpleExecute: beginStatement]; [self simpleExecute: beginStatement];
/* NB. We leave the lock locked ... until a matching -commit
* or -rollback is called. This prevents other threads from
* intefering with this transaction.
*/
} }
NS_HANDLER NS_HANDLER
{ {
@ -1129,19 +1133,22 @@ static unsigned int maxConnections = 8;
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"commit used outside transaction"]; format: @"commit used outside transaction"];
} }
/* Since we are in a transaction we must be doubly locked right now,
* so we unlock once, and we still have the lock (which was locked
* in the earlier call to the -begin method).
*/
[lock unlock];
_inTransaction = NO;
NS_DURING NS_DURING
{ {
[self simpleExecute: commitStatement]; [self simpleExecute: commitStatement];
_inTransaction = NO;
[_statements removeAllObjects]; [_statements removeAllObjects];
[lock unlock]; // Locked at start of -commit
[lock unlock]; // Locked by -begin [lock unlock]; // Locked by -begin
} }
NS_HANDLER NS_HANDLER
{ {
_inTransaction = NO;
[_statements removeAllObjects]; [_statements removeAllObjects];
[lock unlock]; // Locked at start of -commit
[lock unlock]; // Locked by -begin [lock unlock]; // Locked by -begin
[localException raise]; [localException raise];
} }
@ -1654,24 +1661,31 @@ static unsigned int maxConnections = 8;
- (void) rollback - (void) rollback
{ {
[lock lock]; [lock lock];
if (_inTransaction == YES) if (NO == _inTransaction)
{ {
_inTransaction = NO; [lock unlock]; // Not in a transaction ... nothing to do.
[_statements removeAllObjects]; return;
NS_DURING
{
[self simpleExecute: rollbackStatement];
[lock unlock]; // Locked at start of -rollback
[lock unlock]; // Locked by -begin
}
NS_HANDLER
{
[lock unlock]; // Locked at start of -rollback
[lock unlock]; // Locked by -begin
[localException raise];
}
NS_ENDHANDLER
} }
/* Since we are in a transaction we must be doubly locked right now,
* so we unlock once, and we still have the lock (which was locked
* in the earlier call to the -begin method).
*/
[lock unlock];
_inTransaction = NO;
NS_DURING
{
[self simpleExecute: rollbackStatement];
[_statements removeAllObjects];
[lock unlock]; // Locked by -begin
}
NS_HANDLER
{
[_statements removeAllObjects];
[lock unlock]; // Locked by -begin
[localException raise];
}
NS_ENDHANDLER
} }
- (void) setDatabase: (NSString*)s - (void) setDatabase: (NSString*)s