Skip to content

Commit

Permalink
fix preprocessor flags
Browse files Browse the repository at this point in the history
fix deadlock in processMemoryWarning method
  • Loading branch information
Kentzo committed Oct 21, 2010
1 parent 6fa5332 commit f9ecda2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
7 changes: 3 additions & 4 deletions MAFuture.h
Expand Up @@ -6,8 +6,7 @@ id MALazyFuture(id (^block)(void));
#define MALazyFuture(...) ((__typeof((__VA_ARGS__)()))MALazyFuture((id (^)(void))(__VA_ARGS__)))


#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if (TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2) || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
#ifdef __IPHONE_4_0

#pragma mark -

Expand All @@ -16,6 +15,7 @@ id IKMemoryAwareFutureCreate(id (^block)(void));
void IKMemoryAwareFutureBeginContentAccess(id future);
void IKMemoryAwareFutureEndContentAccess(id future);
BOOL IKMemoryAwareFutureIsObserving(id future);
void IKInvalidateMemoryAwareFuture(id future);

#define IKMemoryAwareFuture(...)((__typeof((__VA_ARGS__)()))IKMemoryAwareFuture((id (^)(void))(__VA_ARGS__)))
#define IKMemoryAwareFutureCreate(...)((__typeof((__VA_ARGS__)()))IKMemoryAwareFutureCreate((id (^)(void))(__VA_ARGS__)))
Expand All @@ -29,5 +29,4 @@ id IKAutoArchivingMemoryAwareFutureCreate(id (^block)(void));

#define IKAutoArchivingMemoryAwareFutureCreate(...)((__typeof((__VA_ARGS__)()))IKAutoArchivingMemoryAwareFutureCreate((id (^)(void))(__VA_ARGS__)))

#endif // (TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2) || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED
#endif // __IPHONE_4_0
17 changes: 8 additions & 9 deletions MAFuture.m
Expand Up @@ -121,8 +121,7 @@ id MALazyFuture(id (^block)(void))
#pragma mark -
#pragma mark iOS Futures

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if (TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2) || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
#ifdef __IPHONE_4_0

@implementation _IKMemoryAwareFuture
@synthesize isObserving;
Expand Down Expand Up @@ -200,11 +199,8 @@ - (id)resolveFuture {
- (void)processMemoryWarning {
[_lock lock];
[self setIsObservingUnlocked:NO];
NSThread *thread = [NSThread currentThread];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self processMemoryWarningUnlocked];
[_lock performSelector:@selector(unlock) onThread:thread withObject:nil waitUntilDone:NO];
});
[self processMemoryWarningUnlocked];
[_lock unlock];
}


Expand Down Expand Up @@ -238,6 +234,10 @@ BOOL IKMemoryAwareFutureIsObserving(id future) {
return [future isObserving];
}

void IKInvalidateMemoryAwareFuture(id future) {
[future processMemoryWarning];
}

NSString* IKMemoryAwareFuturesDirectory() {
static NSString* FuturesDirectory = nil;
if (FuturesDirectory == nil) {
Expand Down Expand Up @@ -352,5 +352,4 @@ id IKAutoArchivingMemoryAwareFuture(id (^block)(void)) {
return [IKAutoArchivingMemoryAwareFutureCreate(block) autorelease];
}

#endif // (TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2) || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED
#endif // __IPHONE_4_0
6 changes: 2 additions & 4 deletions MAFutureInternal.h
Expand Up @@ -15,8 +15,7 @@

@end

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if (TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2) || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
#ifdef __IPHONE_4_0

@interface _IKMemoryAwareFuture : _MALazyBlockFuture {
BOOL isObserving;
Expand Down Expand Up @@ -72,5 +71,4 @@ NSString* IKMemoryAwareFuturePath(id future);

@end

#endif // (TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2) || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED
#endif // __IPHONE_4_0
4 changes: 2 additions & 2 deletions MAMethodSignatureCache.h
Expand Up @@ -3,11 +3,11 @@

@interface MAMethodSignatureCache : NSObject
{
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#ifdef __IPHONE_4_0
CFMutableDictionaryRef _cache;
#else
NSMapTable *_cache;
#endif
#endif // __IPHONE_4_0
NSRecursiveLock *_lock;
}

Expand Down
16 changes: 8 additions & 8 deletions MAMethodSignatureCache.m
Expand Up @@ -35,14 +35,14 @@ - (id)init
{
if((self = [super init]))
{
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#ifdef __IPHONE_4_0
_cache = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks);
#else
_cache = [[NSMapTable alloc]
initWithKeyOptions: NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality
valueOptions: NSPointerFunctionsStrongMemory | NSPointerFunctionsObjectPersonality
capacity: 0];
#endif
#endif // __IPHONE_4_0
_lock = [[NSRecursiveLock alloc] init];
[[NSNotificationCenter defaultCenter]
addObserver: self
Expand All @@ -56,11 +56,11 @@ - (id)init
- (void)_clearCache
{
[_lock ma_do: ^{
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#ifdef __IPHONE_4_0
CFDictionaryRemoveAllValues(_cache);
#else
[_cache removeAllObjects];
#endif
#endif // __IPHONE_4_0
}];
}

Expand Down Expand Up @@ -105,21 +105,21 @@ - (NSMethodSignature *)cachedMethodSignatureForSelector: (SEL)sel
{
__block NSMethodSignature *sig = nil;
[_lock ma_do: ^{
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#ifdef __IPHONE_4_0
sig = CFDictionaryGetValue(_cache, sel);
#else
sig = [_cache objectForKey: (id)sel];
#endif
#endif // __IPHONE_4_0
if(!sig)
{
sig = [self _searchAllClassesForSignature: sel];
if(!sig)
sig = (id)[NSNull null];
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#ifdef __IPHONE_4_0
CFDictionarySetValue(_cache, sel, sig);
#else
[_cache setObject: sig forKey: (id)sel];
#endif
#endif //__IPHONE_4_0
}
}];
if(sig == (id)[NSNull null])
Expand Down

0 comments on commit f9ecda2

Please sign in to comment.