Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 80e1dc8b6559bea7aea0d2bdcf831d51f6661e76 1 parent 4282568
erik chen erikchen authored
Showing with 2 additions and 4 deletions.
  1. +2 −4 Classes/ASIHTTPRequest.m
6 Classes/ASIHTTPRequest.m
View
@@ -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];
}
Please sign in to comment.
Something went wrong with that request. Please try again.