Skip to content

Commit

Permalink
Synchronize access to SDWebImageManager's mutable structures (fix #301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Poitrey committed Feb 16, 2013
1 parent a8a3983 commit b27d571
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions SDWebImage/SDWebImageManager.m
Expand Up @@ -83,7 +83,10 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
return operation;
}

[self.runningOperations addObject:operation];
@synchronized(self.runningOperations)
{
[self.runningOperations addObject:operation];
}
NSString *key = [self cacheKeyForURL:url];

[self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType)
Expand All @@ -93,7 +96,10 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
if (image)
{
completedBlock(image, nil, cacheType, YES);
[self.runningOperations removeObject:operation];
@synchronized(self.runningOperations)
{
[self.runningOperations removeObject:operation];
}
}
else
{
Expand All @@ -108,7 +114,10 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
{
if (error.code != NSURLErrorNotConnectedToInternet)
{
[self.failedURLs addObject:url];
@synchronized(self.failedURLs)
{
[self.failedURLs addObject:url];
}
}
}
else if (downloadedImage && finished)
Expand All @@ -119,7 +128,10 @@ - (NSString *)cacheKeyForURL:(NSURL *)url

if (finished)
{
[self.runningOperations removeObject:operation];
@synchronized(self.runningOperations)
{
[self.runningOperations removeObject:operation];
}
}
}];
operation.cancelBlock = ^{[subOperation cancel];};
Expand All @@ -131,8 +143,11 @@ - (NSString *)cacheKeyForURL:(NSURL *)url

- (void)cancelAll
{
[self.runningOperations makeObjectsPerformSelector:@selector(cancel)];
[self.runningOperations removeAllObjects];
@synchronized(self.runningOperations)
{
[self.runningOperations makeObjectsPerformSelector:@selector(cancel)];
[self.runningOperations removeAllObjects];
}
}

- (BOOL)isRunning
Expand Down

0 comments on commit b27d571

Please sign in to comment.