Authored by Lizhen Hu

Replace @synchronized lock with dispatch_semaphore lock for SDWebImageCombinedOperation

@@ -347,10 +347,24 @@ @@ -347,10 +347,24 @@
347 @end 347 @end
348 348
349 349
  350 +@interface SDWebImageCombinedOperation ()
  351 +
  352 +@property (strong, nonatomic, nonnull) dispatch_semaphore_t cancelLock; // a lock to make the `cancel` method thread-safe
  353 +
  354 +@end
  355 +
350 @implementation SDWebImageCombinedOperation 356 @implementation SDWebImageCombinedOperation
351 357
  358 +- (instancetype)init {
  359 + self = [super init];
  360 + if (self) {
  361 + _cancelLock = dispatch_semaphore_create(1);
  362 + }
  363 + return self;
  364 +}
  365 +
352 - (void)cancel { 366 - (void)cancel {
353 - @synchronized(self) { 367 + LOCK(self.cancelLock);
354 self.cancelled = YES; 368 self.cancelled = YES;
355 if (self.cacheOperation) { 369 if (self.cacheOperation) {
356 [self.cacheOperation cancel]; 370 [self.cacheOperation cancel];
@@ -360,7 +374,7 @@ @@ -360,7 +374,7 @@
360 [self.manager.imageDownloader cancel:self.downloadToken]; 374 [self.manager.imageDownloader cancel:self.downloadToken];
361 } 375 }
362 [self.manager safelyRemoveOperationFromRunning:self]; 376 [self.manager safelyRemoveOperationFromRunning:self];
363 - } 377 + UNLOCK(self.cancelLock);
364 } 378 }
365 379
366 @end 380 @end