adium 3124:07fd549d9be0: Ensure only one singleton instance is c...
commits at adium.im
commits at adium.im
Fri Feb 12 18:24:39 UTC 2010
details: http://hg.adium.im/adium/rev/07fd549d9be0
revision: 3124:07fd549d9be0
author: Stephen Holt <sholt at adium.im>
date: Fri Feb 12 12:36:46 2010 -0500
Ensure only one singleton instance is created, and remove locking from init method.
Subject: adium 3125:e1b92eaa3d2d: This +initialize method is completely pointless....
details: http://hg.adium.im/adium/rev/e1b92eaa3d2d
revision: 3125:e1b92eaa3d2d
author: Stephen Holt <sholt at adium.im>
date: Fri Feb 12 13:02:45 2010 -0500
This +initialize method is completely pointless....
Subject: adium 3126:9edd41d61fe9: Bring this static var declarition into it's only use scope.
details: http://hg.adium.im/adium/rev/9edd41d61fe9
revision: 3126:9edd41d61fe9
author: Stephen Holt <sholt at adium.im>
date: Fri Feb 12 13:11:59 2010 -0500
Bring this static var declarition into it's only use scope.
Subject: adium 3127:63afe99d997e: static global variables are guarenteed to be initialized to zero, making this +initialize method redundant.
details: http://hg.adium.im/adium/rev/63afe99d997e
revision: 3127:63afe99d997e
author: Stephen Holt <sholt at adium.im>
date: Fri Feb 12 13:23:42 2010 -0500
static global variables are guarenteed to be initialized to zero, making this +initialize method redundant.
diffs (155 lines):
diff -r 0d23b901cae8 -r 63afe99d997e Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m
--- a/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m Fri Feb 12 12:05:08 2010 -0500
+++ b/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m Fri Feb 12 13:23:42 2010 -0500
@@ -11,10 +11,11 @@
#import <arpa/inet.h>
#import <netdb.h>
#import <netinet/in.h>
+#import <libkern/OSAtomic.h>
#define CONNECTIVITY_DEBUG FALSE
-static AIHostReachabilityMonitor *singleton = nil;
+static AIHostReachabilityMonitor *sharedMonitor = nil;
@interface AIHostReachabilityMonitor ()
- (void)scheduleReachabilityMonitoringForHost:(NSString *)nodename observer:(id)observer;
@@ -40,11 +41,13 @@
*/
+ (id)defaultMonitor
{
- if (!singleton) {
- singleton = [[AIHostReachabilityMonitor alloc] init];
+ if (!sharedMonitor) {
+ AIHostReachabilityMonitor *newMonitor = [[AIHostReachabilityMonitor alloc] init];
+ if(!OSAtomicCompareAndSwapPtrBarrier(nil, newMonitor, (void *)&sharedMonitor))
+ [newMonitor release];
}
- return singleton;
+ return sharedMonitor;
}
#pragma mark -
@@ -59,15 +62,12 @@
hostAndObserverListLock = [[NSLock alloc] init];
[hostAndObserverListLock setName:@"HostAndObserverListLock"];
- [hostAndObserverListLock lock];
hosts = [[NSMutableArray alloc] init];
observers = [[NSMutableArray alloc] init];
reachabilities = [[NSMutableArray alloc] init];
unconfiguredHostsAndObservers = [[NSMutableSet alloc] init];
ipChangesRunLoopSourceRef = nil;
-
- [hostAndObserverListLock unlock];
//Monitor system sleep so we can accurately report connectivity changes when the system wakes
[[NSNotificationCenter defaultCenter] addObserver:self
diff -r 0d23b901cae8 -r 63afe99d997e Frameworks/AIUtilities Framework/Source/AITooltipUtilities.m
--- a/Frameworks/AIUtilities Framework/Source/AITooltipUtilities.m Fri Feb 12 12:05:08 2010 -0500
+++ b/Frameworks/AIUtilities Framework/Source/AITooltipUtilities.m Fri Feb 12 13:23:42 2010 -0500
@@ -14,6 +14,7 @@
\------------------------------------------------------------------------------------------------------ */
#import "AITooltipUtilities.h"
+#import <libkern/OSAtomic.h>
#define TOOLTIP_MAX_WIDTH 300
#define TOOLTIP_INSET 4.0f
@@ -50,17 +51,6 @@
static NSPoint tooltipPoint;
static AITooltipOrientation tooltipOrientation;
-static NSColor *titleAndBodyMarginLineColor = nil;
-
-+ (void)initialize
-{
- if (self != [AITooltipUtilities class])
- return;
- if (!titleAndBodyMarginLineColor) {
- titleAndBodyMarginLineColor = [[[NSColor grayColor] colorWithAlphaComponent:.7f] retain];
- }
-}
-
//Tooltips
+ (void)showTooltipWithString:(NSString *)inString onWindow:(NSWindow *)inWindow atPoint:(NSPoint)inPoint orientation:(AITooltipOrientation)inOrientation
{
@@ -292,12 +282,21 @@
+ (void)_sizeTooltip
{
+ static NSColor *titleAndBodyMarginLineColor = nil;
NSRect tooltipTitleRect;
NSRect tooltipBodyRect;
NSRect tooltipWindowRect;
BOOL hasTitle = tooltipTitle && [tooltipTitle length];
BOOL hasBody = tooltipBody && [tooltipBody length];
+
+ //init titleAndBodyMarginLineColor only once (Drop 10.5 and use blocks, dispatch_once)
+ if(!titleAndBodyMarginLineColor) {
+ NSColor *newTitleAndBodyMarginLineColor = [[[NSColor grayColor] colorWithAlphaComponent:.7f] retain];
+ if(!OSAtomicCompareAndSwapPtrBarrier(nil, newTitleAndBodyMarginLineColor, (void *)&titleAndBodyMarginLineColor))
+ [newTitleAndBodyMarginLineColor release];
+ }
+
if (hasTitle) {
//Make sure we're not wrapping by default
//Set up the tooltip's bounds
diff -r 0d23b901cae8 -r 63afe99d997e Plugins/Bonjour/libezv/Simple HTTP Server/HTTPServer.m
--- a/Plugins/Bonjour/libezv/Simple HTTP Server/HTTPServer.m Fri Feb 12 12:05:08 2010 -0500
+++ b/Plugins/Bonjour/libezv/Simple HTTP Server/HTTPServer.m Fri Feb 12 13:23:42 2010 -0500
@@ -255,23 +255,6 @@
/**
- * This method is automatically called (courtesy of Cocoa) before the first instantiation of this class.
- * We use it to initialize any static variables.
-**/
-+ (void)initialize
-{
- if (self != [HTTPConnection class])
- return;
- static BOOL initialized = NO;
- if (!initialized)
- {
-
- initialized = YES;
- }
-}
-
-
-/**
* Sole Constructor.
* Associates this new HTTP connection with the given AsyncSocket.
* This HTTP connection object will become the socket's delegate and take over responsibility for the socket.
diff -r 0d23b901cae8 -r 63afe99d997e Source/ESContactAlertsController.m
--- a/Source/ESContactAlertsController.m Fri Feb 12 12:05:08 2010 -0500
+++ b/Source/ESContactAlertsController.m Fri Feb 12 13:23:42 2010 -0500
@@ -34,24 +34,6 @@
static NSMutableDictionary *globalOnlyEventHandlersByGroup[EVENT_HANDLER_GROUP_COUNT];
/*!
- * @brief Initialize before the class is used
- */
-+ (void)initialize
-{
- if (self != [ESContactAlertsController class])
- return;
- static BOOL didInitialize = NO;
- if (!didInitialize) {
- for (NSInteger i = 0; i < EVENT_HANDLER_GROUP_COUNT; i++) {
- eventHandlersByGroup[i] = nil;
- globalOnlyEventHandlersByGroup[i] = nil;
- }
-
- didInitialize = YES;
- }
-}
-
-/*!
* @brief Init
*/
- (id)init
More information about the commits
mailing list