aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-07-02 23:46:51 +0200
committerMax <post@wickenrode.com>2015-07-02 23:46:51 +0200
commitc124db7ac403cdd92cc2c26e572f37f7b7d4ae75 (patch)
tree401d9839f330ad88e57dba86ae8f0c7230d5c6d8 /Source
parent3c49b0f2bc16777f83cf57825448b6689ed344e1 (diff)
downloadsequelpro-c124db7ac403cdd92cc2c26e572f37f7b7d4ae75.tar.gz
sequelpro-c124db7ac403cdd92cc2c26e572f37f7b7d4ae75.tar.bz2
sequelpro-c124db7ac403cdd92cc2c26e572f37f7b7d4ae75.zip
Add some info which might help a bit with debugging threading issues
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConnectionController.m4
-rw-r--r--Source/SPConnectionHandler.m2
-rw-r--r--Source/SPCustomQuery.m2
-rw-r--r--Source/SPDataImport.m10
-rw-r--r--Source/SPDatabaseDocument.h6
-rw-r--r--Source/SPDatabaseDocument.m12
-rw-r--r--Source/SPDatabaseStructure.m2
-rw-r--r--Source/SPDatabaseViewController.m4
-rw-r--r--Source/SPExportController.m2
-rw-r--r--Source/SPHistoryController.m2
-rw-r--r--Source/SPIndexesController.m4
-rw-r--r--Source/SPNavigatorController.m2
-rw-r--r--Source/SPTableContent.m6
-rw-r--r--Source/SPTableContentDelegate.m2
-rw-r--r--Source/SPTableStructure.m4
-rw-r--r--Source/SPTableStructureLoading.m2
-rw-r--r--Source/SPTablesList.m14
-rw-r--r--Source/SPThreadAdditions.h22
-rw-r--r--Source/SPThreadAdditions.m14
19 files changed, 80 insertions, 36 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 5af38274..1f3521e9 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -310,7 +310,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
// Cancel the MySQL connection - handing it off to a background thread - if one is present
if (mySQLConnection) {
[mySQLConnection setDelegate:nil];
- [NSThread detachNewThreadWithName:@"SPConnectionController cancellation background disconnect" target:mySQLConnection selector:@selector(disconnect) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionController cancellation background disconnect",dbDocument) target:mySQLConnection selector:@selector(disconnect) object:nil];
[mySQLConnection autorelease];
mySQLConnection = nil;
}
@@ -1871,7 +1871,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
if (mySQLConnection) {
[mySQLConnection setDelegate:nil];
- [NSThread detachNewThreadWithName:@"SPConnectionController close background disconnect" target:mySQLConnection selector:@selector(disconnect) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionController close background disconnect", dbDocument) target:mySQLConnection selector:@selector(disconnect) object:nil];
[mySQLConnection autorelease];
mySQLConnection = nil;
}
diff --git a/Source/SPConnectionHandler.m b/Source/SPConnectionHandler.m
index c216142f..aeb4eb36 100644
--- a/Source/SPConnectionHandler.m
+++ b/Source/SPConnectionHandler.m
@@ -86,7 +86,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1";
[connectButton display];
#endif
- [NSThread detachNewThreadWithName:@"SPConnectionHandler MySQL connection task" target:self selector:@selector(initiateMySQLConnectionInBackground) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionHandler MySQL connection task", dbDocument) target:self selector:@selector(initiateMySQLConnectionInBackground) object:nil];
}
/**
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index a6e14b34..15839a7e 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -585,7 +585,7 @@
// If a helper thread is already running, execute inline - otherwise detach a new thread for the queries
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPCustomQuery query perform task" target:self selector:@selector(performQueriesTask:) object:taskArguments];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPCustomQuery query perform task", tableDocumentInstance) target:self selector:@selector(performQueriesTask:) object:taskArguments];
}
else {
[self performQueriesTask:taskArguments];
diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m
index 30ef3bf4..aa50a827 100644
--- a/Source/SPDataImport.m
+++ b/Source/SPDataImport.m
@@ -257,7 +257,7 @@
if (importFileName == nil) return;
// Begin import process
- [NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDataImport background import task",tableDocumentInstance) target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
}
@@ -326,7 +326,7 @@
if (importFileName == nil) return;
// Begin the import process
- [NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDataImport background import task",tableDocumentInstance) target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
}];
}
@@ -336,7 +336,7 @@
- (void)startSQLImportProcessWithFile:(NSString *)filename
{
[importFormatPopup selectItemWithTitle:@"SQL"];
- [NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:filename];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDataImport background import task",tableDocumentInstance) target:self selector:@selector(_importBackgroundProcess:) object:filename];
}
#pragma mark -
@@ -667,7 +667,7 @@
[tablesListInstance updateTables:self];
// Re-query the structure of all databases in the background
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
// Import finished Growl notification
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Import Finished"
@@ -1183,7 +1183,7 @@
[tablesListInstance performSelectorOnMainThread:@selector(updateTables:) withObject:self waitUntilDone:YES];
// Re-query the structure of all databases in the background
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
// Select the new table
[tablesListInstance selectItemWithName:selectedTableTarget];
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index 23b22d4a..a29f91cc 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -60,13 +60,14 @@
#import "SPDatabaseContentViewDelegate.h"
#import "SPConnectionControllerDelegateProtocol.h"
+#import "SPThreadAdditions.h"
#import <SPMySQL/SPMySQLConnectionDelegate.h>
/**
* The SPDatabaseDocument class controls the primary database view window.
*/
-@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol, SPMySQLConnectionDelegate, NSTextFieldDelegate, NSToolbarDelegate>
+@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol, SPMySQLConnectionDelegate, NSTextFieldDelegate, NSToolbarDelegate, SPCountedObject>
{
#ifdef SP_CODA /* patch */
id delegate;
@@ -283,6 +284,8 @@
#endif
SPDatabaseStructure *databaseStructureRetrieval;
SPGotoDatabaseController *gotoDatabaseController;
+
+ int64_t instanceId;
}
#ifdef SP_CODA /* ivars */
@@ -320,6 +323,7 @@
#endif
@property (readonly) SPServerSupport *serverSupport;
@property (readonly) SPDatabaseStructure *databaseStructureRetrieval;
+@property (readonly) int64_t instanceId;
#ifndef SP_CODA /* method decls */
- (BOOL)isUntitled;
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 3b095f96..faabb2a8 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -113,9 +113,12 @@ enum {
#import <SPMySQL/SPMySQL.h>
+#include <libkern/OSAtomic.h>
+
// Constants
static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
+static int64_t SPDatabaseDocumentInstanceCounter = 0;
@interface SPDatabaseDocument ()
@@ -168,13 +171,14 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
@synthesize chooseDatabaseButton;
@synthesize structureContentSwitcher;
#endif
+@synthesize instanceId;
#pragma mark -
- (id)init
{
if ((self = [super init])) {
-
+ instanceId = OSAtomicIncrement64(&SPDatabaseDocumentInstanceCounter);
#ifndef SP_CODA /* init ivars */
_mainNibLoaded = NO;
@@ -594,7 +598,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[self startTaskWithDescription:NSLocalizedString(@"Restoring session...", @"Restoring session task description")];
if ([NSThread isMainThread])
- [NSThread detachNewThreadWithName:@"SPDatabaseDocument session load task" target:self selector:@selector(restoreSession) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseDocument session load task",self) target:self selector:@selector(restoreSession) object:nil];
else
[self restoreSession];
}
@@ -779,7 +783,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
NSDictionary *selectionDetails = [NSDictionary dictionaryWithObjectsAndKeys:database, @"database", item, @"item", nil];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPDatabaseDocument database and table load task" target:self selector:@selector(_selectDatabaseAndItem:) object:selectionDetails];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseDocument database and table load task",self) target:self selector:@selector(_selectDatabaseAndItem:) object:selectionDetails];
}
else {
[self _selectDatabaseAndItem:selectionDetails];
@@ -1023,7 +1027,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
[self _addDatabase];
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:databaseStructureRetrieval selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",self) target:databaseStructureRetrieval selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
}
else {
// Reset chooseDatabaseButton
diff --git a/Source/SPDatabaseStructure.m b/Source/SPDatabaseStructure.m
index 2eab3562..83ba38bb 100644
--- a/Source/SPDatabaseStructure.m
+++ b/Source/SPDatabaseStructure.m
@@ -102,7 +102,7 @@
- (void)setConnectionToClone:(SPMySQLConnection *)aConnection
{
// Perform the task in a background thread to avoid blocking the UI
- [NSThread detachNewThreadWithName:@"SPDatabaseStructure clone connection task"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseStructure clone connection task",delegate)
target:self
selector:@selector(_cloneConnectionFromConnection:)
object:aConnection];
diff --git a/Source/SPDatabaseViewController.m b/Source/SPDatabaseViewController.m
index ea2186cc..f0ee65d5 100644
--- a/Source/SPDatabaseViewController.m
+++ b/Source/SPDatabaseViewController.m
@@ -303,7 +303,7 @@
[self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), [self table]]];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPDatabaseViewController view load task"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseViewController view load task",self)
target:self
selector:@selector(_loadTabTask:)
object:tabViewItem];
@@ -388,7 +388,7 @@
// If on the main thread, fire up a thread to deal with view changes and data loading;
// if already on a background thread, make the changes on the existing thread.
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPDatabaseViewController table load task"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseViewController table load task",self)
target:self
selector:@selector(_loadTableTask)
object:nil];
diff --git a/Source/SPExportController.m b/Source/SPExportController.m
index c13e4fc6..b0c543cf 100644
--- a/Source/SPExportController.m
+++ b/Source/SPExportController.m
@@ -1026,7 +1026,7 @@ static const NSString *SPSQLExportDropEnabled = @"SQLExportDropEnabled";
[uiStateDict setObject:[NSNumber numberWithInteger:[exportSQLIncludeContentCheck state]] forKey:SPSQLExportContentEnabled];
[uiStateDict setObject:[NSNumber numberWithInteger:[exportSQLIncludeDropSyntaxCheck state]] forKey:SPSQLExportDropEnabled];
- [NSThread detachNewThreadWithName:@"SPExportController export button updater" target:self selector:@selector(_toggleExportButton:) object:uiStateDict];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPExportController export button updater",tableDocumentInstance) target:self selector:@selector(_toggleExportButton:) object:uiStateDict];
[uiStateDict release];
}
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
index 87cc4eab..11442308 100644
--- a/Source/SPHistoryController.m
+++ b/Source/SPHistoryController.m
@@ -385,7 +385,7 @@
// Start the task and perform the load
[theDocument startTaskWithDescription:NSLocalizedString(@"Loading history entry...", @"Loading history entry task desc")];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPHistoryController load of history entry" target:self selector:@selector(loadEntryTaskWithPosition:) object:[NSNumber numberWithUnsignedInteger:position]];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPHistoryController load of history entry", theDocument) target:self selector:@selector(loadEntryTaskWithPosition:) object:[NSNumber numberWithUnsignedInteger:position]];
} else {
[self loadEntryTaskWithPosition:[NSNumber numberWithUnsignedInteger:position]];
}
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m
index 93466c27..0eca239c 100644
--- a/Source/SPIndexesController.m
+++ b/Source/SPIndexesController.m
@@ -657,7 +657,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
#endif
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPIndexesController index creation thread" target:self selector:@selector(_addIndexUsingDetails:) object:indexDetails];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPIndexesController index creation thread", dbDocument) target:self selector:@selector(_addIndexUsingDetails:) object:indexDetails];
[dbDocument enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button") callbackObject:self callbackFunction:NULL];
}
@@ -685,7 +685,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[indexDetails setObject:[NSNumber numberWithBool:[(NSString *)contextInfo hasSuffix:@"AndForeignKey"]] forKey:@"RemoveForeignKey"];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPIndexesController index removal thread" target:self selector:@selector(_removeIndexUsingDetails:) object:indexDetails];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPIndexesController index removal thread", dbDocument) target:self selector:@selector(_removeIndexUsingDetails:) object:indexDetails];
[dbDocument enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button") callbackObject:self callbackFunction:NULL];
}
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index 3f194b24..1c7bfbba 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -610,7 +610,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
if (![[doc getConnection] isConnected]) return;
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[doc databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", doc) target:[doc databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
}
- (IBAction)outlineViewAction:(id)sender
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 113bda45..b3f4d385 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -1308,7 +1308,7 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Reloading data...", @"Reloading data task description")];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableContent table reload task" target:self selector:@selector(reloadTableTask) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent table reload task", tableDocumentInstance) target:self selector:@selector(reloadTableTask) object:nil];
} else {
[self reloadTableTask];
}
@@ -1420,7 +1420,7 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
[tableDocumentInstance startTaskWithDescription:taskString];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableContent filter table task" target:self selector:@selector(filterTableTask) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent filter table task", tableDocumentInstance) target:self selector:@selector(filterTableTask) object:nil];
} else {
[self filterTableTask];
}
@@ -2478,7 +2478,7 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
// If on the main thread, fire up a thread to perform the load while keeping the modification flag
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Loading reference...", @"Loading referece task string")];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableContent linked data load task" target:self selector:@selector(clickLinkArrowTask:) object:theArrowCell];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent linked data load task", tableDocumentInstance) target:self selector:@selector(clickLinkArrowTask:) object:theArrowCell];
} else {
[self clickLinkArrowTask:theArrowCell];
}
diff --git a/Source/SPTableContentDelegate.m b/Source/SPTableContentDelegate.m
index 07c355b9..01252d4e 100644
--- a/Source/SPTableContentDelegate.m
+++ b/Source/SPTableContentDelegate.m
@@ -77,7 +77,7 @@
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Sorting table...", @"Sorting table task description")];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableContent table sort task" target:self selector:@selector(sortTableTaskWithColumn:) object:tableColumn];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent table sort task", tableDocumentInstance) target:self selector:@selector(sortTableTaskWithColumn:) object:tableColumn];
}
else {
[self sortTableTaskWithColumn:tableColumn];
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index cdc1c8c7..1e0c9f5e 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -535,7 +535,7 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
NSNumber *removeKey = [NSNumber numberWithBool:[(NSString *)contextInfo isEqualToString:SPRemoveFieldAndForeignKey]];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableStructure field and key removal task"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPTableStructure field and key removal task", tableDocumentInstance)
target:self
selector:@selector(_removeFieldAndForeignKey:)
object:removeKey];
@@ -969,7 +969,7 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
[tableDocumentInstance setContentRequiresReload:YES];
// Query the structure of all databases in the background
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:[NSDictionary dictionaryWithObjectsAndKeys:@YES, @"forceUpdate", selectedTable, @"affectedItem", [NSNumber numberWithInteger:[tablesListInstance tableType]], @"affectedItemType", nil]];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:[NSDictionary dictionaryWithObjectsAndKeys:@YES, @"forceUpdate", selectedTable, @"affectedItem", [NSNumber numberWithInteger:[tablesListInstance tableType]], @"affectedItemType", nil]];
return YES;
}
diff --git a/Source/SPTableStructureLoading.m b/Source/SPTableStructureLoading.m
index 1950c32e..5a1e8e10 100644
--- a/Source/SPTableStructureLoading.m
+++ b/Source/SPTableStructureLoading.m
@@ -287,7 +287,7 @@
[tableDocumentInstance setStatusRequiresReload:YES];
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance)
target:[tableDocumentInstance databaseStructureRetrieval]
selector:@selector(queryDbStructureWithUserInfo:)
object:@{@"forceUpdate" : @YES}];
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 74523da3..34a14082 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -357,10 +357,10 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
// Query the structure of all databases in the background
if (sender == self)
// Invoked by SP
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:nil];
else
// User press refresh button ergo force update
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES, @"cancelQuerying" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES, @"cancelQuerying" : @YES}];
}
/**
@@ -1611,7 +1611,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#endif
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
}
#ifndef SP_CODA
@@ -2266,7 +2266,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#endif
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance)
target:[tableDocumentInstance databaseStructureRetrieval]
selector:@selector(queryDbStructureWithUserInfo:)
object:@{@"forceUpdate" : @YES}];
@@ -2323,7 +2323,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
{
// Ensure the task is performed on a background thread to group addition and loads
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTablesList table addition task" target:self selector:@selector(_addTable) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPTablesList table addition task", tableDocumentInstance) target:self selector:@selector(_addTable) object:nil];
return;
}
@@ -2417,7 +2417,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#endif
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier"
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance)
target:[tableDocumentInstance databaseStructureRetrieval]
selector:@selector(queryDbStructureWithUserInfo:)
object:@{@"forceUpdate" : @YES}];
@@ -2630,7 +2630,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[tableDocumentInstance loadTable:selectedTableName ofType:selectedTableType];
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
}
#endif
diff --git a/Source/SPThreadAdditions.h b/Source/SPThreadAdditions.h
index 7cad9b71..6e5c4aac 100644
--- a/Source/SPThreadAdditions.h
+++ b/Source/SPThreadAdditions.h
@@ -35,3 +35,25 @@
+ (void)detachNewThreadWithName:(NSString *)aName target:(id)aTarget selector:(SEL)aSelector object:(id)anArgument;
@end
+
+@protocol SPCountedObject <NSObject>
+/**
+ * @return An arbitrary number that is constant for this object (ie. it never changes after init)
+ * and unique for the class during the whole runtime of the application
+ *
+ * This is used with the SPCtxt() function to distinguish threaded operations.
+ * While it would have been simpler to just use the object's memory address as
+ * ID that is not unique enough (e.g. another object can malloc the same memory
+ * freed by an earlier object)
+ */
+- (int64_t)instanceId;
+@end
+
+/**
+ * The string returned by this function should be passed to aName
+ * above in order to distinguish multiple threads (operating on different data
+ * sets) in the debugger / crash reports.
+ * (e.g. two connection tabs doing the "same" stuff).
+ * object should be a distinguishing object (ie. the SPDatabaseDocument *)
+ */
+NSString * SPCtxt(NSString *description,NSObject<SPCountedObject> *object);
diff --git a/Source/SPThreadAdditions.m b/Source/SPThreadAdditions.m
index f61b6289..91a7a99d 100644
--- a/Source/SPThreadAdditions.m
+++ b/Source/SPThreadAdditions.m
@@ -95,3 +95,17 @@
}
@end
+
+#pragma mark -
+
+NSString * SPCtxt(NSString *description,NSObject<SPCountedObject> *object)
+{
+ NSString *idString = @"nil";
+ if(object) {
+ idString = [object className];
+ if([object respondsToSelector:@selector(instanceId)]) {
+ idString = [idString stringByAppendingFormat:@"#%lld", [object instanceId]];
+ }
+ }
+ return [NSString stringWithFormat:@"%@ (%@)",description,idString];
+}