From 185a29c013fdf8b43ef7dc5e95da4c1aa8df34e0 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 23 Jun 2014 02:04:50 +0100 Subject: Move console button and entry generation to occurring non-synchronously when calling back to the main thread, fixing a potential spinlock situation when a background thread is querying and the main thread is waiting on the result --- Source/SPQueryController.m | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'Source') diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index feaa1624..f31ce808 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -44,6 +44,7 @@ NSString *SPTableViewConnectionColumnID = @"messageConnection"; @interface SPQueryController () - (void)_updateFilterState; +- (void)_allowFilterClearOrSave:(NSNumber *)enabled; - (BOOL)_messageMatchesCurrentFilters:(NSString *)message; - (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections; - (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error; @@ -438,8 +439,7 @@ static SPQueryController *sharedQueryController = nil; [progressIndicator startAnimation:self]; // Don't allow clearing the console while filtering its content - [saveConsoleButton setEnabled:NO]; - [clearConsoleButton setEnabled:NO]; + [self _allowFilterClearOrSave:[NSNumber numberWithBool:NO]]; [messagesFilteredSet removeAllObjects]; @@ -451,8 +451,7 @@ static SPQueryController *sharedQueryController = nil; [consoleTableView reloadData]; [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; - [saveConsoleButton setEnabled:YES]; - [clearConsoleButton setEnabled:YES]; + [self _allowFilterClearOrSave:[NSNumber numberWithBool:YES]]; [saveConsoleButton setTitle:NSLocalizedString(@"Save As...", @"save as button title")]; @@ -484,8 +483,7 @@ static SPQueryController *sharedQueryController = nil; [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; if ([messagesVisibleSet count] > 0) { - [saveConsoleButton setEnabled:YES]; - [clearConsoleButton setEnabled:YES]; + [self _allowFilterClearOrSave:[NSNumber numberWithBool:YES]]; } [saveConsoleButton setTitle:NSLocalizedString(@"Save View As...", @"save view as button title")]; @@ -496,6 +494,15 @@ static SPQueryController *sharedQueryController = nil; #endif } +/** + * Enable or disable console save and clear buttons + */ +- (void)_allowFilterClearOrSave:(NSNumber *)enabled +{ + [saveConsoleButton setEnabled:[enabled boolValue]]; + [clearConsoleButton setEnabled:[enabled boolValue]]; +} + /** * Checks whether the supplied message text matches the current filter text, if any, * and whether it should be hidden if the SELECT/SHOW toggle is off. @@ -592,13 +599,12 @@ static SPQueryController *sharedQueryController = nil; && [self _messageMatchesCurrentFilters:[consoleMessage message]]) { [messagesFilteredSet addObject:[messagesFullSet lastObject]]; - [[saveConsoleButton onMainThread] setEnabled:YES]; - [[clearConsoleButton onMainThread] setEnabled:YES]; + [self performSelectorOnMainThread:@selector(_allowFilterClearOrSave:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:NO]; } // Reload the table and scroll to the new message if it's visible (for speed) if (allowConsoleUpdate && [[self window] isVisible]) { - [[self onMainThread] updateEntries]; + [self performSelectorOnMainThread:@selector(updateEntries) withObject:nil waitUntilDone:NO]; } pthread_mutex_unlock(&consoleLock); -- cgit v1.2.3