From 6ddd95658062b14de2f63746f69b6d65d05792d4 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 13 Oct 2009 20:44:37 +0000 Subject: - Tweak query locking with MCPStreamingResults to fix certain operations releasing locks on different threads from which they were locked (which generates a console message) --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 1 + Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 23 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'Frameworks/MCPKit') diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 8a9e2567..604b69d5 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -203,6 +203,7 @@ void performThreadedKeepAlive(void *ptr); - (my_ulonglong)insertId; // Locking +- (void)lockConnection; - (void)unlockConnection; // Database structure diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 86261d4d..4e6e0ada 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -1352,7 +1352,14 @@ void performThreadedKeepAlive(void *ptr) } } - [queryLock lock]; + // Lock on this thread for normal result sets... + if (streamResultType == MCP_NO_STREAMING) { + [queryLock lock]; + + // ...but streaming result unlock on the main thread after processing, so ensure a lock on the main thread. + } else { + [self lockConnection]; + } // Run (or re-run) the query, timing the execution time of the query - note // that this time will include network lag. @@ -1480,11 +1487,21 @@ void performThreadedKeepAlive(void *ptr) #pragma mark Connection locking /** - * Unlock the connection + * Lock the connection from any thread + */ +- (void)lockConnection +{ + if ([NSThread isMainThread]) [queryLock lock]; + else [queryLock performSelectorOnMainThread:@selector(lock) withObject:nil waitUntilDone:YES]; +} + +/** + * Unlock the connection from any thread */ - (void)unlockConnection { - [queryLock performSelectorOnMainThread:@selector(unlock) withObject:nil waitUntilDone:YES]; + if ([NSThread isMainThread]) [queryLock unlock]; + else [queryLock performSelectorOnMainThread:@selector(unlock) withObject:nil waitUntilDone:YES]; } #pragma mark - -- cgit v1.2.3