aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-03-19 14:43:07 +0000
committerrowanbeentje <rowan@beent.je>2010-03-19 14:43:07 +0000
commit604fa161ddefaa64833307a994507de7b538a7b6 (patch)
tree79bdc3b1b926af19084b033cd1fea9ec41d577e6 /Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
parent3f3690fd0ffe43c3986789cf64bcdd25597eed1e (diff)
downloadsequelpro-604fa161ddefaa64833307a994507de7b538a7b6.tar.gz
sequelpro-604fa161ddefaa64833307a994507de7b538a7b6.tar.bz2
sequelpro-604fa161ddefaa64833307a994507de7b538a7b6.zip
- Clean up connection unlocking to prevent race conditions causing logged warnings
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m12
1 files changed, 7 insertions, 5 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 83260b82..3223964c 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -1669,14 +1669,16 @@ void performThreadedKeepAlive(void *ptr)
- (void)unlockConnection
{
- // Make sure the unlock is performed safely - eg for reconnected queries
- if ([queryLock tryLock]) {
- [queryLock unlock];
+ // Ensure the unlock occurs on the main thread
+ if (![NSThread isMainThread]) {
+ [self performSelectorOnMainThread:@selector(unlockConnection) withObject:nil waitUntilDone:NO];
return;
}
- if ([NSThread isMainThread]) [queryLock unlock];
- else [queryLock performSelectorOnMainThread:@selector(unlock) withObject:nil waitUntilDone:NO];
+ // Unlock the connection, first ensuring it is locked to avoid
+ // multiple unlock call issues (eg reconnected queries, threading)
+ [queryLock tryLock];
+ [queryLock unlock];
}
#pragma mark -