Skip to content

Commit

Permalink
Fix threading issue in -[DFImageManager startPreheatingImagesForReque…
Browse files Browse the repository at this point in the history
…sts:] method
  • Loading branch information
kean committed May 14, 2015
1 parent 7145337 commit 72db88c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions DFImageManager/Source/Core/Managing/DFImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,13 @@ - (void)updateOperationPriority {

@interface DFImageManager () <_DFImageRequestKeyDelegate>

@property (nonatomic, readonly) NSMutableSet *executingImageTasks;
@property (nonatomic, readonly) NSMutableDictionary /* _DFImageRequestKey : _DFImageTask */ *preheatingTasks;
@property (nonatomic, readonly) NSMutableDictionary /* _DFImageRequestKey : _DFImageFetchOperation */ *fetchOperations;

@end

@implementation DFImageManager {
dispatch_queue_t _queue;
NSMutableSet *_executingImageTasks;
NSMutableDictionary /* _DFImageRequestKey : _DFImageFetchOperation */ *_fetchOperations;
NSMutableDictionary /* _DFImageRequestKey : _DFImageTask */ *_preheatingTasks;
NSInteger _preheatingTaskCounter;
BOOL _needsToExecutePreheatTasks;
BOOL _fetcherRespondsToCanonicalRequest;
Expand Down Expand Up @@ -422,7 +421,12 @@ - (void)startPreheatingImagesForRequests:(NSArray *)requests {
if (!_preheatingTasks[key]) {
DFImageManager *__weak weakSelf = self;
_DFImageTask *handler = [[_DFImageTask alloc] initWithManager:self request:request completionHandler:^(UIImage *image, NSDictionary *info) {
[weakSelf.preheatingTasks removeObjectForKey:key];
DFImageManager *strongSelf = weakSelf;
if (strongSelf) {
dispatch_async(strongSelf->_queue, ^{
[strongSelf->_preheatingTasks removeObjectForKey:key];
});
}
}];
handler.tag = _preheatingTaskCounter++;
_preheatingTasks[key] = handler;
Expand Down

0 comments on commit 72db88c

Please sign in to comment.