diff options
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 1 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 23 |
2 files changed, 21 insertions, 3 deletions
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 - |