Authored by Olivier Poitrey

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

@@ -83,7 +83,10 @@ @@ -83,7 +83,10 @@
83 return operation; 83 return operation;
84 } 84 }
85 85
86 - [self.runningOperations addObject:operation]; 86 + @synchronized(self.runningOperations)
  87 + {
  88 + [self.runningOperations addObject:operation];
  89 + }
87 NSString *key = [self cacheKeyForURL:url]; 90 NSString *key = [self cacheKeyForURL:url];
88 91
89 [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType) 92 [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType)
@@ -93,7 +96,10 @@ @@ -93,7 +96,10 @@
93 if (image) 96 if (image)
94 { 97 {
95 completedBlock(image, nil, cacheType, YES); 98 completedBlock(image, nil, cacheType, YES);
96 - [self.runningOperations removeObject:operation]; 99 + @synchronized(self.runningOperations)
  100 + {
  101 + [self.runningOperations removeObject:operation];
  102 + }
97 } 103 }
98 else 104 else
99 { 105 {
@@ -108,7 +114,10 @@ @@ -108,7 +114,10 @@
108 { 114 {
109 if (error.code != NSURLErrorNotConnectedToInternet) 115 if (error.code != NSURLErrorNotConnectedToInternet)
110 { 116 {
111 - [self.failedURLs addObject:url]; 117 + @synchronized(self.failedURLs)
  118 + {
  119 + [self.failedURLs addObject:url];
  120 + }
112 } 121 }
113 } 122 }
114 else if (downloadedImage && finished) 123 else if (downloadedImage && finished)
@@ -119,7 +128,10 @@ @@ -119,7 +128,10 @@
119 128
120 if (finished) 129 if (finished)
121 { 130 {
122 - [self.runningOperations removeObject:operation]; 131 + @synchronized(self.runningOperations)
  132 + {
  133 + [self.runningOperations removeObject:operation];
  134 + }
123 } 135 }
124 }]; 136 }];
125 operation.cancelBlock = ^{[subOperation cancel];}; 137 operation.cancelBlock = ^{[subOperation cancel];};
@@ -131,8 +143,11 @@ @@ -131,8 +143,11 @@
131 143
132 - (void)cancelAll 144 - (void)cancelAll
133 { 145 {
134 - [self.runningOperations makeObjectsPerformSelector:@selector(cancel)];  
135 - [self.runningOperations removeAllObjects]; 146 + @synchronized(self.runningOperations)
  147 + {
  148 + [self.runningOperations makeObjectsPerformSelector:@selector(cancel)];
  149 + [self.runningOperations removeAllObjects];
  150 + }
136 } 151 }
137 152
138 - (BOOL)isRunning 153 - (BOOL)isRunning