Skip to content

Commit c124db7

Browse files
committed
Add some info which might help a bit with debugging threading issues
1 parent 3c49b0f commit c124db7

19 files changed

+80
-36
lines changed

Source/SPConnectionController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ - (IBAction)cancelConnection:(id)sender
310310
// Cancel the MySQL connection - handing it off to a background thread - if one is present
311311
if (mySQLConnection) {
312312
[mySQLConnection setDelegate:nil];
313-
[NSThread detachNewThreadWithName:@"SPConnectionController cancellation background disconnect" target:mySQLConnection selector:@selector(disconnect) object:nil];
313+
[NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionController cancellation background disconnect",dbDocument) target:mySQLConnection selector:@selector(disconnect) object:nil];
314314
[mySQLConnection autorelease];
315315
mySQLConnection = nil;
316316
}
@@ -1871,7 +1871,7 @@ - (void)_documentWillClose:(NSNotification *)notification
18711871

18721872
if (mySQLConnection) {
18731873
[mySQLConnection setDelegate:nil];
1874-
[NSThread detachNewThreadWithName:@"SPConnectionController close background disconnect" target:mySQLConnection selector:@selector(disconnect) object:nil];
1874+
[NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionController close background disconnect", dbDocument) target:mySQLConnection selector:@selector(disconnect) object:nil];
18751875
[mySQLConnection autorelease];
18761876
mySQLConnection = nil;
18771877
}

Source/SPConnectionHandler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ - (void)initiateMySQLConnection
8686
[connectButton display];
8787
#endif
8888

89-
[NSThread detachNewThreadWithName:@"SPConnectionHandler MySQL connection task" target:self selector:@selector(initiateMySQLConnectionInBackground) object:nil];
89+
[NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionHandler MySQL connection task", dbDocument) target:self selector:@selector(initiateMySQLConnectionInBackground) object:nil];
9090
}
9191

9292
/**

Source/SPCustomQuery.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ - (void)performQueries:(NSArray *)queries withCallback:(SEL)customQueryCallbackM
585585

586586
// If a helper thread is already running, execute inline - otherwise detach a new thread for the queries
587587
if ([NSThread isMainThread]) {
588-
[NSThread detachNewThreadWithName:@"SPCustomQuery query perform task" target:self selector:@selector(performQueriesTask:) object:taskArguments];
588+
[NSThread detachNewThreadWithName:SPCtxt(@"SPCustomQuery query perform task", tableDocumentInstance) target:self selector:@selector(performQueriesTask:) object:taskArguments];
589589
}
590590
else {
591591
[self performQueriesTask:taskArguments];

Source/SPDataImport.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ - (void)importFromClipboardSheetDidEnd:(id)sheet returnCode:(NSInteger)returnCod
257257
if (importFileName == nil) return;
258258

259259
// Begin import process
260-
[NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
260+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDataImport background import task",tableDocumentInstance) target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
261261
}
262262

263263

@@ -326,7 +326,7 @@ - (void)importFile
326326
if (importFileName == nil) return;
327327

328328
// Begin the import process
329-
[NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
329+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDataImport background import task",tableDocumentInstance) target:self selector:@selector(_importBackgroundProcess:) object:importFileName];
330330
}];
331331
}
332332

@@ -336,7 +336,7 @@ - (void)importFile
336336
- (void)startSQLImportProcessWithFile:(NSString *)filename
337337
{
338338
[importFormatPopup selectItemWithTitle:@"SQL"];
339-
[NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:filename];
339+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDataImport background import task",tableDocumentInstance) target:self selector:@selector(_importBackgroundProcess:) object:filename];
340340
}
341341

342342
#pragma mark -
@@ -667,7 +667,7 @@ - (void)importSQLFile:(NSString *)filename
667667
[tablesListInstance updateTables:self];
668668

669669
// Re-query the structure of all databases in the background
670-
[NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
670+
[NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
671671

672672
// Import finished Growl notification
673673
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Import Finished"
@@ -1183,7 +1183,7 @@ - (void)importCSVFile:(NSString *)filename
11831183
[tablesListInstance performSelectorOnMainThread:@selector(updateTables:) withObject:self waitUntilDone:YES];
11841184

11851185
// Re-query the structure of all databases in the background
1186-
[NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
1186+
[NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",tableDocumentInstance) target:[tableDocumentInstance databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
11871187

11881188
// Select the new table
11891189
[tablesListInstance selectItemWithName:selectedTableTarget];

Source/SPDatabaseDocument.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@
6060

6161
#import "SPDatabaseContentViewDelegate.h"
6262
#import "SPConnectionControllerDelegateProtocol.h"
63+
#import "SPThreadAdditions.h"
6364

6465
#import <SPMySQL/SPMySQLConnectionDelegate.h>
6566

6667
/**
6768
* The SPDatabaseDocument class controls the primary database view window.
6869
*/
69-
@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol, SPMySQLConnectionDelegate, NSTextFieldDelegate, NSToolbarDelegate>
70+
@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol, SPMySQLConnectionDelegate, NSTextFieldDelegate, NSToolbarDelegate, SPCountedObject>
7071
{
7172
#ifdef SP_CODA /* patch */
7273
id delegate;
@@ -283,6 +284,8 @@
283284
#endif
284285
SPDatabaseStructure *databaseStructureRetrieval;
285286
SPGotoDatabaseController *gotoDatabaseController;
287+
288+
int64_t instanceId;
286289
}
287290

288291
#ifdef SP_CODA /* ivars */
@@ -320,6 +323,7 @@
320323
#endif
321324
@property (readonly) SPServerSupport *serverSupport;
322325
@property (readonly) SPDatabaseStructure *databaseStructureRetrieval;
326+
@property (readonly) int64_t instanceId;
323327

324328
#ifndef SP_CODA /* method decls */
325329
- (BOOL)isUntitled;

Source/SPDatabaseDocument.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@
113113

114114
#import <SPMySQL/SPMySQL.h>
115115

116+
#include <libkern/OSAtomic.h>
117+
116118
// Constants
117119
static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
118120
static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
121+
static int64_t SPDatabaseDocumentInstanceCounter = 0;
119122

120123
@interface SPDatabaseDocument ()
121124

@@ -168,13 +171,14 @@ @implementation SPDatabaseDocument
168171
@synthesize chooseDatabaseButton;
169172
@synthesize structureContentSwitcher;
170173
#endif
174+
@synthesize instanceId;
171175

172176
#pragma mark -
173177

174178
- (id)init
175179
{
176180
if ((self = [super init])) {
177-
181+
instanceId = OSAtomicIncrement64(&SPDatabaseDocumentInstanceCounter);
178182
#ifndef SP_CODA /* init ivars */
179183

180184
_mainNibLoaded = NO;
@@ -594,7 +598,7 @@ - (void)setConnection:(SPMySQLConnection *)theConnection
594598
[self startTaskWithDescription:NSLocalizedString(@"Restoring session...", @"Restoring session task description")];
595599

596600
if ([NSThread isMainThread])
597-
[NSThread detachNewThreadWithName:@"SPDatabaseDocument session load task" target:self selector:@selector(restoreSession) object:nil];
601+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseDocument session load task",self) target:self selector:@selector(restoreSession) object:nil];
598602
else
599603
[self restoreSession];
600604
}
@@ -779,7 +783,7 @@ - (void)selectDatabase:(NSString *)database item:(NSString *)item
779783
NSDictionary *selectionDetails = [NSDictionary dictionaryWithObjectsAndKeys:database, @"database", item, @"item", nil];
780784

781785
if ([NSThread isMainThread]) {
782-
[NSThread detachNewThreadWithName:@"SPDatabaseDocument database and table load task" target:self selector:@selector(_selectDatabaseAndItem:) object:selectionDetails];
786+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseDocument database and table load task",self) target:self selector:@selector(_selectDatabaseAndItem:) object:selectionDetails];
783787
}
784788
else {
785789
[self _selectDatabaseAndItem:selectionDetails];
@@ -1023,7 +1027,7 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
10231027
[self _addDatabase];
10241028

10251029
// Query the structure of all databases in the background (mainly for completion)
1026-
[NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:databaseStructureRetrieval selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
1030+
[NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier",self) target:databaseStructureRetrieval selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
10271031
}
10281032
else {
10291033
// Reset chooseDatabaseButton

Source/SPDatabaseStructure.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ - (id)initWithDelegate:(SPDatabaseDocument *)theDelegate
102102
- (void)setConnectionToClone:(SPMySQLConnection *)aConnection
103103
{
104104
// Perform the task in a background thread to avoid blocking the UI
105-
[NSThread detachNewThreadWithName:@"SPDatabaseStructure clone connection task"
105+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseStructure clone connection task",delegate)
106106
target:self
107107
selector:@selector(_cloneConnectionFromConnection:)
108108
object:aConnection];

Source/SPDatabaseViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabV
303303
[self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), [self table]]];
304304

305305
if ([NSThread isMainThread]) {
306-
[NSThread detachNewThreadWithName:@"SPDatabaseViewController view load task"
306+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseViewController view load task",self)
307307
target:self
308308
selector:@selector(_loadTabTask:)
309309
object:tabViewItem];
@@ -388,7 +388,7 @@ - (void)loadTable:(NSString *)aTable ofType:(SPTableType)aTableType
388388
// If on the main thread, fire up a thread to deal with view changes and data loading;
389389
// if already on a background thread, make the changes on the existing thread.
390390
if ([NSThread isMainThread]) {
391-
[NSThread detachNewThreadWithName:@"SPDatabaseViewController table load task"
391+
[NSThread detachNewThreadWithName:SPCtxt(@"SPDatabaseViewController table load task",self)
392392
target:self
393393
selector:@selector(_loadTableTask)
394394
object:nil];

Source/SPExportController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ - (void)_toggleExportButtonOnBackgroundThread
10261026
[uiStateDict setObject:[NSNumber numberWithInteger:[exportSQLIncludeContentCheck state]] forKey:SPSQLExportContentEnabled];
10271027
[uiStateDict setObject:[NSNumber numberWithInteger:[exportSQLIncludeDropSyntaxCheck state]] forKey:SPSQLExportDropEnabled];
10281028

1029-
[NSThread detachNewThreadWithName:@"SPExportController export button updater" target:self selector:@selector(_toggleExportButton:) object:uiStateDict];
1029+
[NSThread detachNewThreadWithName:SPCtxt(@"SPExportController export button updater",tableDocumentInstance) target:self selector:@selector(_toggleExportButton:) object:uiStateDict];
10301030

10311031
[uiStateDict release];
10321032
}

Source/SPHistoryController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ - (void) loadEntryAtPosition:(NSUInteger)position
385385
// Start the task and perform the load
386386
[theDocument startTaskWithDescription:NSLocalizedString(@"Loading history entry...", @"Loading history entry task desc")];
387387
if ([NSThread isMainThread]) {
388-
[NSThread detachNewThreadWithName:@"SPHistoryController load of history entry" target:self selector:@selector(loadEntryTaskWithPosition:) object:[NSNumber numberWithUnsignedInteger:position]];
388+
[NSThread detachNewThreadWithName:SPCtxt(@"SPHistoryController load of history entry", theDocument) target:self selector:@selector(loadEntryTaskWithPosition:) object:[NSNumber numberWithUnsignedInteger:position]];
389389
} else {
390390
[self loadEntryTaskWithPosition:[NSNumber numberWithUnsignedInteger:position]];
391391
}

Source/SPIndexesController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ - (void)addIndexSheetDidEnd:(NSWindow *)theSheet returnCode:(NSInteger)returnCod
657657
#endif
658658

659659
if ([NSThread isMainThread]) {
660-
[NSThread detachNewThreadWithName:@"SPIndexesController index creation thread" target:self selector:@selector(_addIndexUsingDetails:) object:indexDetails];
660+
[NSThread detachNewThreadWithName:SPCtxt(@"SPIndexesController index creation thread", dbDocument) target:self selector:@selector(_addIndexUsingDetails:) object:indexDetails];
661661

662662
[dbDocument enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button") callbackObject:self callbackFunction:NULL];
663663
}
@@ -685,7 +685,7 @@ - (void)removeIndexSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode
685685
[indexDetails setObject:[NSNumber numberWithBool:[(NSString *)contextInfo hasSuffix:@"AndForeignKey"]] forKey:@"RemoveForeignKey"];
686686

687687
if ([NSThread isMainThread]) {
688-
[NSThread detachNewThreadWithName:@"SPIndexesController index removal thread" target:self selector:@selector(_removeIndexUsingDetails:) object:indexDetails];
688+
[NSThread detachNewThreadWithName:SPCtxt(@"SPIndexesController index removal thread", dbDocument) target:self selector:@selector(_removeIndexUsingDetails:) object:indexDetails];
689689

690690
[dbDocument enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button") callbackObject:self callbackFunction:NULL];
691691
}

Source/SPNavigatorController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ - (IBAction)reloadAllStructures:(id)sender
610610

611611
if (![[doc getConnection] isConnected]) return;
612612

613-
[NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier" target:[doc databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
613+
[NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", doc) target:[doc databaseStructureRetrieval] selector:@selector(queryDbStructureWithUserInfo:) object:@{@"forceUpdate" : @YES}];
614614
}
615615

616616
- (IBAction)outlineViewAction:(id)sender

Source/SPTableContent.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ - (IBAction)reloadTable:(id)sender
13081308
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Reloading data...", @"Reloading data task description")];
13091309

13101310
if ([NSThread isMainThread]) {
1311-
[NSThread detachNewThreadWithName:@"SPTableContent table reload task" target:self selector:@selector(reloadTableTask) object:nil];
1311+
[NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent table reload task", tableDocumentInstance) target:self selector:@selector(reloadTableTask) object:nil];
13121312
} else {
13131313
[self reloadTableTask];
13141314
}
@@ -1420,7 +1420,7 @@ - (IBAction)filterTable:(id)sender
14201420
[tableDocumentInstance startTaskWithDescription:taskString];
14211421

14221422
if ([NSThread isMainThread]) {
1423-
[NSThread detachNewThreadWithName:@"SPTableContent filter table task" target:self selector:@selector(filterTableTask) object:nil];
1423+
[NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent filter table task", tableDocumentInstance) target:self selector:@selector(filterTableTask) object:nil];
14241424
} else {
14251425
[self filterTableTask];
14261426
}
@@ -2478,7 +2478,7 @@ - (void)clickLinkArrow:(SPTextAndLinkCell *)theArrowCell
24782478
// If on the main thread, fire up a thread to perform the load while keeping the modification flag
24792479
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Loading reference...", @"Loading referece task string")];
24802480
if ([NSThread isMainThread]) {
2481-
[NSThread detachNewThreadWithName:@"SPTableContent linked data load task" target:self selector:@selector(clickLinkArrowTask:) object:theArrowCell];
2481+
[NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent linked data load task", tableDocumentInstance) target:self selector:@selector(clickLinkArrowTask:) object:theArrowCell];
24822482
} else {
24832483
[self clickLinkArrowTask:theArrowCell];
24842484
}

Source/SPTableContentDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ - (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)t
7777
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Sorting table...", @"Sorting table task description")];
7878

7979
if ([NSThread isMainThread]) {
80-
[NSThread detachNewThreadWithName:@"SPTableContent table sort task" target:self selector:@selector(sortTableTaskWithColumn:) object:tableColumn];
80+
[NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent table sort task", tableDocumentInstance) target:self selector:@selector(sortTableTaskWithColumn:) object:tableColumn];
8181
}
8282
else {
8383
[self sortTableTaskWithColumn:tableColumn];

Source/SPTableStructure.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ - (void)removeFieldSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode
535535
NSNumber *removeKey = [NSNumber numberWithBool:[(NSString *)contextInfo isEqualToString:SPRemoveFieldAndForeignKey]];
536536

537537
if ([NSThread isMainThread]) {
538-
[NSThread detachNewThreadWithName:@"SPTableStructure field and key removal task"
538+
[NSThread detachNewThreadWithName:SPCtxt(@"SPTableStructure field and key removal task", tableDocumentInstance)
539539
target:self
540540
selector:@selector(_removeFieldAndForeignKey:)
541541
object:removeKey];
@@ -969,7 +969,7 @@ - (BOOL)addRowToDB
969969
[tableDocumentInstance setContentRequiresReload:YES];
970970

971971
// Query the structure of all databases in the background
972-
[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]];
972+
[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]];
973973

974974
return YES;
975975
}

Source/SPTableStructureLoading.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ - (IBAction)reloadTable:(id)sender
287287
[tableDocumentInstance setStatusRequiresReload:YES];
288288

289289
// Query the structure of all databases in the background (mainly for completion)
290-
[NSThread detachNewThreadWithName:@"SPNavigatorController database structure querier"
290+
[NSThread detachNewThreadWithName:SPCtxt(@"SPNavigatorController database structure querier", tableDocumentInstance)
291291
target:[tableDocumentInstance databaseStructureRetrieval]
292292
selector:@selector(queryDbStructureWithUserInfo:)
293293
object:@{@"forceUpdate" : @YES}];

0 commit comments

Comments
 (0)