diff --git a/SDWebImage/SDWebImageCompat.h b/SDWebImage/SDWebImageCompat.h index e950a6ac..2a6caa38 100644 --- a/SDWebImage/SDWebImageCompat.h +++ b/SDWebImage/SDWebImageCompat.h @@ -99,11 +99,15 @@ typedef void(^SDWebImageNoParamsBlock)(void); FOUNDATION_EXPORT NSString *const SDWebImageErrorDomain; -#ifndef dispatch_main_async_safe -#define dispatch_main_async_safe(block)\ - if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\ +#ifndef dispatch_queue_async_safe +#define dispatch_queue_async_safe(queue, block)\ + if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(queue)) == 0) {\ block();\ } else {\ - dispatch_async(dispatch_get_main_queue(), block);\ + dispatch_async(queue, block);\ } #endif + +#ifndef dispatch_main_async_safe +#define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block) +#endif diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index 20b944cd..b3734be4 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -106,7 +106,7 @@ static char TAG_ACTIVITY_SHOW; } dispatch_queue_t targetQueue = shouldUseGlobalQueue ? dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0) : dispatch_get_main_queue(); - dispatch_async(targetQueue, ^{ + dispatch_queue_async_safe(targetQueue, ^{ [sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock]; dispatch_main_async_safe(callCompletedBlockClojure); });