From 15a9a678170c20671e86c5fa18393e1c5bddaff4 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 26 Sep 2010 20:18:01 +0000 Subject: Implement threading locking when modifying the query console/controller's log data storage to prevent race conditions. Should fix crash: http://spbug.com/l/1644 --- Source/SPQueryController.h | 2 ++ Source/SPQueryController.m | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index 797d5b6b..9c8a9c8f 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -57,6 +57,8 @@ NSUserDefaults *prefs; NSDateFormatter *dateFormatter; + + pthread_mutex_t consoleLock; } @property (readwrite, retain) NSFont *consoleFont; diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index eb0e8a1a..ec7e6b70 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -29,6 +29,8 @@ #import "SPConstants.h" #import "SPCustomQuery.h" +#import "pthread.h" + #define MESSAGE_TRUNCATE_CHARACTER_LENGTH 256 // Table view column identifiers @@ -96,6 +98,8 @@ static SPQueryController *sharedQueryController = nil; completionKeywordList = nil; completionFunctionList = nil; functionArgumentSnippets = nil; + + pthread_mutex_init(&consoleLock, NULL); NSError *readError = nil; NSString *convError = nil; @@ -824,6 +828,9 @@ static SPQueryController *sharedQueryController = nil; if(completionKeywordList) [completionKeywordList release]; if(completionFunctionList) [completionFunctionList release]; if(functionArgumentSnippets) [functionArgumentSnippets release]; + + pthread_mutex_destroy(&consoleLock); + [super dealloc]; } @@ -981,6 +988,8 @@ static SPQueryController *sharedQueryController = nil; [consoleMessage setIsError:error]; + pthread_mutex_lock(&consoleLock); + [messagesFullSet addObject:consoleMessage]; // If filtering is active, determine whether to add a reference to the filtered set @@ -998,6 +1007,8 @@ static SPQueryController *sharedQueryController = nil; [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; [consoleTableView reloadData]; } + + pthread_mutex_unlock(&consoleLock); } @end -- cgit v1.2.3