Skip to content
This repository
Browse code

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 1 changed file with 2 additions and 4 deletions. Show diff stats Hide diff stats

  1. +2 4 Classes/ASIHTTPRequest.m
6 Classes/ASIHTTPRequest.m
@@ -3507,7 +3507,7 @@ - (void)handleStreamComplete
3507 3507
3508 3508 // If request has asked delegate or ASIAuthenticationDialog for credentials
3509 3509 } else if ([self authenticationNeeded]) {
3510   - CFRunLoopStop(CFRunLoopGetCurrent());
  3510 + // Do nothing.
3511 3511 }
3512 3512
3513 3513 }
@@ -3547,8 +3547,6 @@ - (void)markAsFinished
3547 3547 if (!wasFinished)
3548 3548 [self didChangeValueForKey:@"isFinished"];
3549 3549
3550   - CFRunLoopStop(CFRunLoopGetCurrent());
3551   -
3552 3550 #if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
3553 3551 if ([ASIHTTPRequest isMultitaskingSupported] && [self shouldContinueWhenAppEntersBackground]) {
3554 3552 dispatch_async(dispatch_get_main_queue(), ^{
@@ -4787,7 +4785,7 @@ + (void)runRequests
4787 4785 BOOL runAlways = YES; // Introduced to cheat Static Analyzer
4788 4786 while (runAlways) {
4789 4787 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
4790   - CFRunLoopRun();
  4788 + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e10, true);
4791 4789 [pool drain];
4792 4790 }
4793 4791

0 comments on commit 80e1dc8

Please sign in to comment.
Something went wrong with that request. Please try again.