Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Synchronize access to SDWebImageManager's mutable structures (fix #301)

  • Loading branch information...
commit b27d5719c23cb1840601c8b38ac036706d7e6ef0 1 parent a8a3983
@rs authored
Showing with 21 additions and 6 deletions.
  1. +21 −6 SDWebImage/SDWebImageManager.m
View
27 SDWebImage/SDWebImageManager.m
@@ -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)
@@ -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
{
@@ -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)
@@ -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];};
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.