Permalink
Browse files

Clean up the use of CFRunLoop.

Previously, tasks running from inside the CFRunLoop would call CFRunLoopStop prior to finishing execution. This results in non-deterministic failures to call endBackgroundTask when running iOS tasks in the background with beginBackgroundTaskWithExpirationHandler.
Since the only reason to break out of the CFRunLoop is to flush the autorelease pool, we instead invoke CFRunLoopRunInMode with returnAfterSourceHandled=True, which safely returns and flushes the autorelease pool after each invocation of the CFRunLoop.
  • Loading branch information...
1 parent 4282568 commit 80e1dc8b6559bea7aea0d2bdcf831d51f6661e76 @erikchen erikchen committed Oct 18, 2011
Showing with 2 additions and 4 deletions.
  1. +2 −4 Classes/ASIHTTPRequest.m
View
6 Classes/ASIHTTPRequest.m
@@ -3507,7 +3507,7 @@ - (void)handleStreamComplete
// If request has asked delegate or ASIAuthenticationDialog for credentials
} else if ([self authenticationNeeded]) {
- CFRunLoopStop(CFRunLoopGetCurrent());
+ // Do nothing.
}
}
@@ -3547,8 +3547,6 @@ - (void)markAsFinished
if (!wasFinished)
[self didChangeValueForKey:@"isFinished"];
- CFRunLoopStop(CFRunLoopGetCurrent());
-
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
if ([ASIHTTPRequest isMultitaskingSupported] && [self shouldContinueWhenAppEntersBackground]) {
dispatch_async(dispatch_get_main_queue(), ^{
@@ -4787,7 +4785,7 @@ + (void)runRequests
BOOL runAlways = YES; // Introduced to cheat Static Analyzer
while (runAlways) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- CFRunLoopRun();
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e10, true);
[pool drain];
}

0 comments on commit 80e1dc8

Please sign in to comment.