Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add some info which might help a bit with debugging threading issues
  • Loading branch information
dmoagx committed Jul 2, 2015
1 parent 3c49b0f commit c124db7
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Source/SPConnectionController.m
Expand Up @@ -310,7 +310,7 @@ - (IBAction)cancelConnection:(id)sender
// 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;
}
Expand Down Expand Up @@ -1871,7 +1871,7 @@ - (void)_documentWillClose:(NSNotification *)notification

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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SPConnectionHandler.m
Expand Up @@ -86,7 +86,7 @@ - (void)initiateMySQLConnection
[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];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/SPCustomQuery.m
Expand Up @@ -585,7 +585,7 @@ - (void)performQueries:(NSArray *)queries withCallback:(SEL)customQueryCallbackM

// 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];
Expand Down
10 changes: 5 additions & 5 deletions Source/SPDataImport.m
Expand Up @@ -257,7 +257,7 @@ - (void)importFromClipboardSheetDidEnd:(id)sheet returnCode:(NSInteger)returnCod
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];
}


Expand Down Expand Up @@ -326,7 +326,7 @@ - (void)importFile
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];
}];
}

Expand All @@ -336,7 +336,7 @@ - (void)importFile
- (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 -
Expand Down Expand Up @@ -667,7 +667,7 @@ - (void)importSQLFile:(NSString *)filename
[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"
Expand Down Expand Up @@ -1183,7 +1183,7 @@ - (void)importCSVFile:(NSString *)filename
[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];
Expand Down
6 changes: 5 additions & 1 deletion Source/SPDatabaseDocument.h
Expand Up @@ -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;
Expand Down Expand Up @@ -283,6 +284,8 @@
#endif
SPDatabaseStructure *databaseStructureRetrieval;
SPGotoDatabaseController *gotoDatabaseController;

int64_t instanceId;
}

#ifdef SP_CODA /* ivars */
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions Source/SPDatabaseDocument.m
Expand Up @@ -113,9 +113,12 @@

#import <SPMySQL/SPMySQL.h>

#include <libkern/OSAtomic.h>

// Constants
static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
static int64_t SPDatabaseDocumentInstanceCounter = 0;

@interface SPDatabaseDocument ()

Expand Down Expand Up @@ -168,13 +171,14 @@ @implementation SPDatabaseDocument
@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;
Expand Down Expand Up @@ -594,7 +598,7 @@ - (void)setConnection:(SPMySQLConnection *)theConnection
[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];
}
Expand Down Expand Up @@ -779,7 +783,7 @@ - (void)selectDatabase:(NSString *)database item:(NSString *)item
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];
Expand Down Expand Up @@ -1023,7 +1027,7 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
[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
Expand Down
2 changes: 1 addition & 1 deletion Source/SPDatabaseStructure.m
Expand Up @@ -102,7 +102,7 @@ - (id)initWithDelegate:(SPDatabaseDocument *)theDelegate
- (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];
Expand Down
4 changes: 2 additions & 2 deletions Source/SPDatabaseViewController.m
Expand Up @@ -303,7 +303,7 @@ - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabV
[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];
Expand Down Expand Up @@ -388,7 +388,7 @@ - (void)loadTable:(NSString *)aTable ofType:(SPTableType)aTableType
// 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];
Expand Down
2 changes: 1 addition & 1 deletion Source/SPExportController.m
Expand Up @@ -1026,7 +1026,7 @@ - (void)_toggleExportButtonOnBackgroundThread
[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];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SPHistoryController.m
Expand Up @@ -385,7 +385,7 @@ - (void) loadEntryAtPosition:(NSUInteger)position
// 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]];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SPIndexesController.m
Expand Up @@ -657,7 +657,7 @@ - (void)addIndexSheetDidEnd:(NSWindow *)theSheet returnCode:(NSInteger)returnCod
#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];
}
Expand Down Expand Up @@ -685,7 +685,7 @@ - (void)removeIndexSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode
[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];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SPNavigatorController.m
Expand Up @@ -610,7 +610,7 @@ - (IBAction)reloadAllStructures:(id)sender

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
Expand Down
6 changes: 3 additions & 3 deletions Source/SPTableContent.m
Expand Up @@ -1308,7 +1308,7 @@ - (IBAction)reloadTable:(id)sender
[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];
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ - (IBAction)filterTable:(id)sender
[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];
}
Expand Down Expand Up @@ -2478,7 +2478,7 @@ - (void)clickLinkArrow:(SPTextAndLinkCell *)theArrowCell
// 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];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SPTableContentDelegate.m
Expand Up @@ -77,7 +77,7 @@ - (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)t
[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];
Expand Down
4 changes: 2 additions & 2 deletions Source/SPTableStructure.m
Expand Up @@ -535,7 +535,7 @@ - (void)removeFieldSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode
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];
Expand Down Expand Up @@ -969,7 +969,7 @@ - (BOOL)addRowToDB
[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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SPTableStructureLoading.m
Expand Up @@ -287,7 +287,7 @@ - (IBAction)reloadTable:(id)sender
[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}];
Expand Down

0 comments on commit c124db7

Please sign in to comment.