Fix deadlock from trying to do a dispatch_sync on the main queue when already on the main thread

This commit is contained in:
Mike Ash 2013-02-22 17:36:57 -05:00
parent 1e0bce2ba9
commit bea04f4978

View File

@ -993,9 +993,14 @@ static const NSUInteger AFMultipartBodyStreamProviderBufferSize = 4096;
_outputStream = CFBridgingRelease(writeStream);
_outputStream.delegate = self;
dispatch_sync(dispatch_get_main_queue(), ^{
if([NSThread isMainThread]) {
[_outputStream scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
});
}
else {
dispatch_sync(dispatch_get_main_queue(), ^{
[_outputStream scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
});
}
[_outputStream open];
_keepalive = self;
}