From 604fa161ddefaa64833307a994507de7b538a7b6 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Fri, 19 Mar 2010 14:43:07 +0000 Subject: - Clean up connection unlocking to prevent race conditions causing logged warnings --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 12 +++++++----- 1 file 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 - -- cgit v1.2.3