Changeset 3533
- Timestamp:
- 01/04/07 20:30:58 (2 years ago)
- Files:
-
- trunk/Additions/MVUtilities.h (modified) (4 diffs)
- trunk/Additions/NSNotificationAdditions.m (modified) (3 diffs)
- trunk/Chat Core/MVIRCChatConnection.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Additions/MVUtilities.h
r3532 r3533 1 #import < Foundation/NSObjCRuntime.h>1 #import <pthread.h> 2 2 3 NS_INLINE void MVSafeAssign( id *var, id newValue ) { 3 #define MVInline static __inline__ __attribute__((always_inline)) 4 5 MVInline void MVSafeAssign( id *var, id newValue ) { 4 6 if( *var == newValue ) 5 7 return; … … 9 11 } 10 12 11 NS_INLINEvoid MVSafeRetainAssign( id *var, id newValue ) {13 MVInline void MVSafeRetainAssign( id *var, id newValue ) { 12 14 if( *var == newValue ) 13 15 return; … … 17 19 } 18 20 19 NS_INLINEvoid MVSafeCopyAssign( id *var, id newValue ) {21 MVInline void MVSafeCopyAssign( id *var, id newValue ) { 20 22 if( *var == newValue ) 21 23 return; … … 25 27 } 26 28 27 NS_INLINEid MVSafeReturn( id var ) {29 MVInline id MVSafeReturn( id var ) { 28 30 return [[var retain] autorelease]; 29 31 } 30 32 31 33 #define MVAssertMainThreadRequired() \ 32 NSAssert1( [NSThread isMainThread], @"Method needs to run on the main thread, not %@.", [NSThread currentThread] )34 NSAssert1( pthread_main_np(), @"Method needs to run on the main thread, not %@.", [NSThread currentThread] ) 33 35 34 36 #define MVAssertCorrectThreadRequired(thread) \ trunk/Additions/NSNotificationAdditions.m
r3532 r3533 1 1 #import "NSNotificationAdditions.h" 2 #import <pthread.h> 2 3 3 4 @implementation NSNotificationCenter (NSNotificationCenterAdditions) 4 5 - (void) postNotificationOnMainThread:(NSNotification *) notification { 5 if( [NSThread isMainThread]) return [self postNotification:notification];6 if( pthread_main_np() ) return [self postNotification:notification]; 6 7 [self postNotificationOnMainThread:notification waitUntilDone:NO]; 7 8 } 8 9 9 10 - (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait { 10 if( [NSThread isMainThread]) return [self postNotification:notification];11 if( pthread_main_np() ) return [self postNotification:notification]; 11 12 [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait]; 12 13 } … … 17 18 18 19 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object { 19 if( [NSThread isMainThread]) return [self postNotificationName:name object:object userInfo:nil];20 if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil]; 20 21 [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO]; 21 22 } 22 23 23 24 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo { 24 if( [NSThread isMainThread]) return [self postNotificationName:name object:object userInfo:userInfo];25 if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; 25 26 [self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO]; 26 27 } 27 28 28 29 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait { 29 if( [NSThread isMainThread]) return [self postNotificationName:name object:object userInfo:userInfo];30 if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; 30 31 31 32 NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:3]; … … 50 51 @implementation NSNotificationQueue (NSNotificationQueueAdditions) 51 52 - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle { 52 if( [NSThread isMainThread]) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil];53 if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 53 54 [self enqueueNotificationOnMainThread:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 54 55 } 55 56 56 57 - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle coalesceMask:(unsigned) coalesceMask forModes:(NSArray *) modes { 57 if( [NSThread isMainThread]) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes];58 if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; 58 59 59 60 NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:4]; trunk/Chat Core/MVIRCChatConnection.m
r3532 r3533 222 222 223 223 - (void) disconnectWithReason:(NSAttributedString *) reason { 224 [self performSelector :@selector( cancelPendingReconnectAttempts ) withObject:nil inThread:[NSThread mainThread]];224 [self performSelectorOnMainThread:@selector( cancelPendingReconnectAttempts ) withObject:nil waitUntilDone:NO]; 225 225 226 226 if( _sendQueueProcessing && _connectionThread )
