adium 2699:e0dddb889014: use fewer depricated classes.

commits at adium.im commits at adium.im
Fri Sep 11 19:09:42 UTC 2009


details:	http://hg.adium.im/adium/rev/e0dddb889014
revision:	2699:e0dddb889014
author:		Stephen Holt <sholt at adium.im>
date:		Fri Sep 11 15:08:48 2009 -0400

use fewer depricated classes.
Subject: adium 2700:33068673e478: Remove the requirement that AISharedWriterQueue need be called from the main thread.

details:	http://hg.adium.im/adium/rev/33068673e478
revision:	2700:33068673e478
author:		Stephen Holt <sholt at adium.im>
date:		Fri Sep 11 15:08:48 2009 -0400

Remove the requirement that AISharedWriterQueue need be called from the main thread.

Use a SpinLock to ensure only one singleton is created, since it's unlikely the call will ever be contested, and when it is, the usual case will be a quick conditional jump.

diffs (69 lines):

diff -r 49ccc121ce98 -r 33068673e478 Frameworks/AIUtilities Framework/Source/AISharedWriterQueue.m
--- a/Frameworks/AIUtilities Framework/Source/AISharedWriterQueue.m	Fri Sep 11 14:32:40 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AISharedWriterQueue.m	Fri Sep 11 15:08:48 2009 -0400
@@ -14,6 +14,7 @@
  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 #import "AISharedWriterQueue.h"
+#import <libkern/OSAtomic.h>
 
 @interface AISharedWriterQueue()
 + (NSOperationQueue *)queue;
@@ -30,12 +31,17 @@
 }
 
 + (NSOperationQueue *)queue {
-	NSAssert([NSThread currentThread] == [NSThread mainThread], @"Do not try to use AISharedWriterQueue from non-main threads");
+	static OSSpinLock spinLock = OS_SPINLOCK_INIT;
 	static NSOperationQueue *sharedWriterQueue = nil;
+	
+	OSSpinLockLock(&spinLock);
+	
 	if (!sharedWriterQueue) {
 		sharedWriterQueue = [[NSOperationQueue alloc] init];
 		[sharedWriterQueue setMaxConcurrentOperationCount:1];
 	}
+	
+	OSSpinLockUnlock(&spinLock);
 	return sharedWriterQueue;
 }
 
diff -r 49ccc121ce98 -r 33068673e478 Plugins/Bonjour/libezv/Private Classes/AWEzvRendezvousData.m
--- a/Plugins/Bonjour/libezv/Private Classes/AWEzvRendezvousData.m	Fri Sep 11 14:32:40 2009 -0400
+++ b/Plugins/Bonjour/libezv/Private Classes/AWEzvRendezvousData.m	Fri Sep 11 15:08:48 2009 -0400
@@ -151,7 +151,7 @@
             tmpData = [NSData dataWithBytes:[data bytes] + i length:fieldLen];
             fieldContent = [[[NSString alloc] initWithData:tmpData encoding:NSUTF8StringEncoding] autorelease];
         } else {
-            fieldContent = [NSString stringWithCString:[data bytes] + i length:fieldLen];
+			fieldContent = [[[NSString alloc] initWithBytes:[data bytes] + i length:fieldLen encoding:NSUTF8StringEncoding] autorelease];
         }
         i = i + fieldLen;
 	
@@ -465,7 +465,7 @@
 	    }
 	    hexdata[[(NSData *)value length] * 2] = '\0';
 	    
-	    [infoData appendString:[NSString stringWithCString:hexdata]];
+	    [infoData appendString:[NSString stringWithUTF8String:hexdata]];
 	} else {
 	    [infoData appendString:value];
 	}
@@ -497,7 +497,7 @@
 			sprintf(hexdata + (i*2), "%.2x", ((unsigned char *)[(NSData *)value bytes])[i]);
 		    }
 		    hexdata[[(NSData *)value length] * 2] = '\0';
-			valueToSet = [[NSString stringWithCString:hexdata] UTF8String];
+			valueToSet = [[NSString stringWithUTF8String:hexdata] UTF8String];
 			valueSize = strlen(valueToSet);
 			free(hexdata);
 		} else {
@@ -575,7 +575,7 @@
 			[infoData appendFormat:@"%c", ([(NSData *)value length] * 2 + [key length] + 1)];
 			[infoData appendString:key];
 			[infoData appendString:@"="];
-			[infoData appendString:[NSString stringWithCString:hexdata]];
+			[infoData appendString:[NSString stringWithUTF8String:hexdata]];
 			free(hexdata);
 		} else {
 			const char *val = [(NSString *)value UTF8String];




More information about the commits mailing list