adium 2701:29fdbbaefd11: Move away from NSThread in AILoggerPlug...

commits at adium.im commits at adium.im
Fri Sep 11 23:45:23 UTC 2009


details:	http://hg.adium.im/adium/rev/29fdbbaefd11
revision:	2701:29fdbbaefd11
author:		Stephen Holt <sholt at adium.im>
date:		Fri Sep 11 19:44:35 2009 -0400

Move away from NSThread in AILoggerPlugin, NSOperationQueue is our new friend.
Subject: adium 2702:fdcd429aa45f: Give the operation queue for AISharedWriterQueue a name, if it's supported.

details:	http://hg.adium.im/adium/rev/fdcd429aa45f
revision:	2702:fdcd429aa45f
author:		Stephen Holt <sholt at adium.im>
date:		Fri Sep 11 19:44:35 2009 -0400

Give the operation queue for AISharedWriterQueue a name, if it's supported.
Subject: adium 2703:060e69d2a592: Move our password lookup threadding from NSThread to NSOperationQueues.

details:	http://hg.adium.im/adium/rev/060e69d2a592
revision:	2703:060e69d2a592
author:		Stephen Holt <sholt at adium.im>
date:		Fri Sep 11 19:45:01 2009 -0400

Move our password lookup threadding from NSThread to NSOperationQueues.

diffs (180 lines):

diff -r 33068673e478 -r 060e69d2a592 Frameworks/AIUtilities Framework/Source/AISharedWriterQueue.m
--- a/Frameworks/AIUtilities Framework/Source/AISharedWriterQueue.m	Fri Sep 11 15:08:48 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AISharedWriterQueue.m	Fri Sep 11 19:45:01 2009 -0400
@@ -39,6 +39,9 @@
 	if (!sharedWriterQueue) {
 		sharedWriterQueue = [[NSOperationQueue alloc] init];
 		[sharedWriterQueue setMaxConcurrentOperationCount:1];
+		if([sharedWriterQueue respondsToSelector:@selector(setName:)]) {
+			[sharedWriterQueue setName:@"AISharedWriterQueue"];
+		}
 	}
 	
 	OSSpinLockUnlock(&spinLock);
diff -r 33068673e478 -r 060e69d2a592 Source/AILoggerPlugin.m
--- a/Source/AILoggerPlugin.m	Fri Sep 11 15:08:48 2009 -0400
+++ b/Source/AILoggerPlugin.m	Fri Sep 11 19:45:01 2009 -0400
@@ -50,6 +50,8 @@
 #import <AIUtilities/NSCalendarDate+ISO8601Unparsing.h>
 #import <AIUtilities/NSCalendarDate+ISO8601Parsing.h>
 
+#import <libkern/OSAtomic.h>
+
 #import "AILogFileUpgradeWindowController.h"
 
 #import "AdiumSpotlightImporter.h"
@@ -79,6 +81,7 @@
 
 @interface AILoggerPlugin ()
 + (NSString *)dereferenceLogFolderAlias;
++ (NSOperationQueue *)operationQueue;
 - (void)configureMenuItems;
 - (SKIndexRef)createLogIndex;
 - (void)closeLogIndex;
@@ -211,6 +214,22 @@
 	[adium.preferenceController removeObserver:self forKeyPath:PREF_KEYPATH_LOGGER_ENABLE];
 }
 
++ (NSOperationQueue *)operationQueue {
+	static OSSpinLock spinLock = OS_SPINLOCK_INIT;
+	static NSOperationQueue *loggerQueue = nil;
+	
+	OSSpinLockLock(&spinLock);
+	if (!loggerQueue) {
+		loggerQueue = [[NSOperationQueue alloc] init];
+		if([loggerQueue respondsToSelector:@selector(setName:)]) {
+			[loggerQueue setName:@"AILoggerPluginOperationQueue"];
+		}
+	}
+	OSSpinLockUnlock(&spinLock);
+	
+	return loggerQueue;
+}
+
 //If logBasePath refers to an alias file, dereference the alias and replace logBasePath with that pathname.
 + (NSString *)dereferenceLogFolderAlias {
 	if (!logBaseAliasPath) {
@@ -1262,9 +1281,10 @@
 		if (index_Content) {
 			AILogWithSignature(@"Triggerring the flushIndex thread and queuing index closing");
 			
-			[NSThread detachNewThreadSelector:@selector(flushIndex:)
-									 toTarget:self
-								   withObject:(id)index_Content];
+			[[AILoggerPlugin operationQueue] addOperation:
+			 [[NSInvocationOperation alloc] initWithTarget:self
+												  selector:@selector(flushIndex:)
+													object:(id)index_Content]];
 			
 			[self cancelClosingLogIndex];
 			[self performSelector:@selector(finishClosingIndex)
@@ -1359,7 +1379,10 @@
     [dirtyLogSet removeAllObjects];
 	[dirtyLogLock unlock];
 	//[self _dirtyAllLogsThread];
-	[NSThread detachNewThreadSelector:@selector(_dirtyAllLogsThread) toTarget:self withObject:nil];
+	[[AILoggerPlugin operationQueue] addOperation:[[NSInvocationOperation alloc]
+												   initWithTarget:self
+												   selector:@selector(_dirtyAllLogsThread)
+												   object:nil]];
 }
 - (void)_dirtyAllLogsThread
 {
@@ -1434,7 +1457,8 @@
     logsIndexed = 0;
 	AILogWithSignature(@"cleanDirtyLogs: logsToIndex is %i",logsToIndex);
 	if (logsToIndex > 0) {
-		[NSThread detachNewThreadSelector:@selector(_cleanDirtyLogsThread:) toTarget:self withObject:(id)[self logContentIndex]];
+		[[AILoggerPlugin operationQueue] addOperation:
+		 [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_cleanDirtyLogsThread:) object:(id)[self logContentIndex]]];
 	}
 }
 
@@ -1627,12 +1651,13 @@
 
 - (void)removePathsFromIndex:(NSSet *)paths
 {
-	[NSThread detachNewThreadSelector:@selector(_removePathsFromIndexThread:)
-							 toTarget:self
-						   withObject:[NSDictionary dictionaryWithObjectsAndKeys:
-							   (id)[self logContentIndex], @"SKIndexRef",
-							   paths, @"Paths",
-							   nil]];
+	[[AILoggerPlugin operationQueue] addOperation:[[NSInvocationOperation alloc]
+												   initWithTarget:self
+												   selector:@selector(_removePathsFromIndexThread:)
+												   object:[NSDictionary dictionaryWithObjectsAndKeys:
+														   (id)[self logContentIndex], @"SKIndexRef",
+														   paths, @"Paths",
+														   nil]]];
 }
 
 
diff -r 33068673e478 -r 060e69d2a592 Source/AdiumPasswords.m
--- a/Source/AdiumPasswords.m	Fri Sep 11 15:08:48 2009 -0400
+++ b/Source/AdiumPasswords.m	Fri Sep 11 19:45:01 2009 -0400
@@ -23,6 +23,7 @@
 #import <AIUtilities/AIObjectAdditions.h>
 #import <AIUtilities/AIStringAdditions.h>
 #import <objc/objc-runtime.h>
+#import <libkern/OSAtomic.h>
 
 #import "AISpecialPasswordPromptController.h"
 #import "ESAccountPasswordPromptController.h"
@@ -31,6 +32,7 @@
 #define KEY_PERFORMED_ACCOUNT_PASSWORD_UPGRADE @"Adium 1.3: Account Passwords Upgraded"
 
 @interface AdiumPasswords ()
++ (NSOperationQueue *)operationQueue;
 - (NSString *)_oldStyleAccountNameForAccount:(AIAccount *)inAccount;
 - (NSString *)_passKeyForAccount:(AIAccount *)inAccount;
 - (NSString *)_accountNameForAccount:(AIAccount *)inAccount;
@@ -53,6 +55,22 @@
 	[self _upgradeAccountPasswordKeychainEntries];
 }
 
++ (NSOperationQueue *)operationQueue {
+	static OSSpinLock spinLock = OS_SPINLOCK_INIT;
+	static NSOperationQueue *passwordQueue = nil;
+	
+	OSSpinLockLock(&spinLock);
+	if (!passwordQueue) {
+		passwordQueue = [[NSOperationQueue alloc] init];
+		if([passwordQueue respondsToSelector:@selector(setName:)]) {
+			[passwordQueue setName:@"AdiumPasswordsOperationQueue"];
+		}
+	}
+	OSSpinLockUnlock(&spinLock);
+	
+	return passwordQueue;
+}
+
 //Accounts -------------------------------------------------------------------------------------------------------------
 #pragma mark Accounts
 
@@ -203,15 +221,16 @@
  */
 - (void)passwordForAccount:(AIAccount *)inAccount promptOption:(AIPromptOption)promptOption notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
 {
-	[NSThread detachNewThreadSelector:@selector(threadedPasswordRetrieval:)
-							 toTarget:self
-						   withObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
-									   inAccount, @"Account",
-									   [NSNumber numberWithInteger:promptOption], @"AIPromptOption",
-									   inTarget, @"Target",
-									   NSStringFromSelector(inSelector), @"Selector",
-									   inContext, @"Context" /* may be nil so should be last */,
-									   nil]];
+	[[AdiumPasswords operationQueue] addOperation:[[NSInvocationOperation alloc]
+												   initWithTarget:self
+												   selector:@selector(threadedPasswordRetrieval:)
+												   object:[NSMutableDictionary dictionaryWithObjectsAndKeys:
+														   inAccount, @"Account",
+														   [NSNumber numberWithInteger:promptOption], @"AIPromptOption",
+														   inTarget, @"Target",
+														   NSStringFromSelector(inSelector), @"Selector",
+														   inContext, @"Context" /* may be nil so should be last */,
+														   nil]]];
 }
 
 //Proxy Servers --------------------------------------------------------------------------------------------------------




More information about the commits mailing list