aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-10-08 02:36:45 +0200
committerMax <post@wickenrode.com>2015-10-08 02:36:45 +0200
commite3b8f07f34cd630bc285357d016e38c1926e362a (patch)
tree79b8bdce43c05a52a25d7fafd237aaab60fbe8a7 /Source
parent9943a8baad6739809e7f8e8ae5a9c9daaf1d6899 (diff)
downloadsequelpro-e3b8f07f34cd630bc285357d016e38c1926e362a.tar.gz
sequelpro-e3b8f07f34cd630bc285357d016e38c1926e362a.tar.bz2
sequelpro-e3b8f07f34cd630bc285357d016e38c1926e362a.zip
* Turn some successive onMainThread ops into a block
* Move a lock() that could become unbalanced and theoretically cause havoc
Diffstat (limited to 'Source')
-rw-r--r--Source/SPDataImport.m53
-rw-r--r--Source/SPFileHandle.m3
2 files changed, 29 insertions, 27 deletions
diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m
index 5cf67976..8ce41afc 100644
--- a/Source/SPDataImport.m
+++ b/Source/SPDataImport.m
@@ -160,15 +160,12 @@
*/
- (void)closeAndStopProgressSheet
{
- if (![NSThread isMainThread]) {
- [self performSelectorOnMainThread:@selector(closeAndStopProgressSheet) withObject:nil waitUntilDone:YES];
- return;
- }
-
- [NSApp endSheet:singleProgressSheet];
- [singleProgressSheet orderOut:nil];
- [[singleProgressBar onMainThread] stopAnimation:self];
- [[singleProgressBar onMainThread] setMaxValue:100];
+ SPMainQSync(^{
+ [NSApp endSheet:singleProgressSheet];
+ [singleProgressSheet orderOut:nil];
+ [singleProgressBar stopAnimation:self];
+ [singleProgressBar setMaxValue:100];
+ });
}
#pragma mark -
@@ -762,16 +759,18 @@
if ([csvFileHandle compressionFormat] == SPBzip2Compression) useIndeterminate = YES;
// Reset progress interface
- [[errorsView onMainThread] setString:@""];
- [[singleProgressTitle onMainThread] setStringValue:NSLocalizedString(@"Importing CSV", @"text showing that the application is importing CSV")];
- [[singleProgressText onMainThread] setStringValue:NSLocalizedString(@"Reading...", @"text showing that app is reading dump")];
- [[singleProgressBar onMainThread] setIndeterminate:YES];
- [[singleProgressBar onMainThread] setUsesThreadedAnimation:YES];
- [[singleProgressBar onMainThread] startAnimation:self];
-
- // Open the progress sheet
- [[NSApp onMainThread] beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
- [[singleProgressSheet onMainThread] makeKeyWindow];
+ SPMainQSync(^{
+ [errorsView setString:@""];
+ [singleProgressTitle setStringValue:NSLocalizedString(@"Importing CSV", @"text showing that the application is importing CSV")];
+ [singleProgressText setStringValue:NSLocalizedString(@"Reading...", @"text showing that app is reading dump")];
+ [singleProgressBar setIndeterminate:YES];
+ [singleProgressBar setUsesThreadedAnimation:YES];
+ [singleProgressBar startAnimation:self];
+
+ // Open the progress sheet
+ [NSApp beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
+ [singleProgressSheet makeKeyWindow];
+ });
[tableDocumentInstance setQueryMode:SPImportExportQueryMode];
@@ -936,11 +935,13 @@
}
// Reset progress interface and open the progress sheet
- [[singleProgressBar onMainThread] setIndeterminate:useIndeterminate];
- [[singleProgressBar onMainThread] setMaxValue:fileTotalLength];
- [[singleProgressBar onMainThread] startAnimation:self];
- [[NSApp onMainThread] beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
- [[singleProgressSheet onMainThread] makeKeyWindow];
+ SPMainQSync(^{
+ [singleProgressBar setIndeterminate:useIndeterminate];
+ [singleProgressBar setMaxValue:fileTotalLength];
+ [singleProgressBar startAnimation:self];
+ [NSApp beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
+ [singleProgressSheet makeKeyWindow];
+ });
// Set up index sets for use during row enumeration
for (i = 0; i < [fieldMappingArray count]; i++) {
@@ -1183,7 +1184,7 @@
// Select the new table
// Update current database tables
- [tablesListInstance performSelectorOnMainThread:@selector(updateTables:) withObject:self waitUntilDone:YES];
+ [[tablesListInstance onMainThread] updateTables:self];
// Re-query the structure of all databases in the background
[NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
@@ -1674,7 +1675,7 @@ cleanup:
- (void)showErrorSheetWithMessage:(NSString*)message
{
if (![NSThread isMainThread]) {
- [self performSelectorOnMainThread:@selector(showErrorSheetWithMessage:) withObject:message waitUntilDone:YES];
+ [[self onMainThread] showErrorSheetWithMessage:message];
return;
}
diff --git a/Source/SPFileHandle.m b/Source/SPFileHandle.m
index 62204252..3971e18b 100644
--- a/Source/SPFileHandle.m
+++ b/Source/SPFileHandle.m
@@ -299,9 +299,10 @@
// Throw an exception if the file is closed
if (fileIsClosed) [NSException raise:NSInternalInconsistencyException format:@"Cannot write to a file handle after it has been closed"];
+ pthread_mutex_lock(&bufferLock);
+
// Add the data to the buffer
if ([data length]) {
- pthread_mutex_lock(&bufferLock);
[buffer appendData:data];
allDataWritten = NO;
bufferDataLength += [data length];