aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-08-29 23:55:35 +0000
committerrowanbeentje <rowan@beent.je>2010-08-29 23:55:35 +0000
commitcdb4b4adda734c94bbef94b92a9479a733858c33 (patch)
treea490dd1ee2cdddde36598fe3ad568fdd3335b6db /Frameworks/MCPKit/MCPFoundationKit
parent8d0ac341f8927040dfd152504dbb1aae93bc16cd (diff)
downloadsequelpro-cdb4b4adda734c94bbef94b92a9479a733858c33.tar.gz
sequelpro-cdb4b4adda734c94bbef94b92a9479a733858c33.tar.bz2
sequelpro-cdb4b4adda734c94bbef94b92a9479a733858c33.zip
- Improve background thread reconnect interaction with the interface; if the application is in a modal state, the background thread waits. This improves interface behaviour on multiple SSH disconnections after sleep/wake (finishing Issue #798) and also disconnections while the interface is modally locked (eg editing text/blobs).
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m13
1 files changed, 10 insertions, 3 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index b619db67..d7cd1fba 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -235,7 +235,9 @@ static BOOL sTruncateLongFieldInLogs = YES;
}
/**
- * Ask the delegate for the connection lost decision, on the main thread.
+ * Ask the delegate for the connection lost decision. This can be called from
+ * any thread, and will call itself on the main thread if necessary, updating a global
+ * variable which is then returned on the child thread.
*/
- (MCPConnectionCheck)delegateDecisionForLostConnection
{
@@ -245,8 +247,9 @@ static BOOL sTruncateLongFieldInLogs = YES;
lastDelegateDecisionForLostConnection = NSNotFound;
- // If on the main thread, ask the delegate directly. Perform this in an NSLock to confirm thread safety,
- // as this method may be called within itself.
+ // If on the main thread, ask the delegate directly.
+ // This is wrapped in a NSLock to ensure variables are completely committed for
+ // thread-safe access, even though the lock is constrained to this code block.
if ([NSThread isMainThread]) {
NSLock *delegateDecisionLock = [[NSLock alloc] init];
[delegateDecisionLock lock];
@@ -256,6 +259,10 @@ static BOOL sTruncateLongFieldInLogs = YES;
// Otherwise call ourself on the main thread, waiting until the reply is received.
} else {
+
+ // First check whether the application is in a modal state; if so, wait
+ while ([NSApp modalWindow]) usleep(100000);
+
[self performSelectorOnMainThread:@selector(delegateDecisionForLostConnection) withObject:nil waitUntilDone:YES];
}