Authored by Bogdan Poplauschi

Replacing #781 - based on http://blog.benjamin-encz.de/post/main-queue-vs-main-t…

…hread/, background queue can execute code on the main thread, so we need to check for the main queue to assure safety
@@ -107,7 +107,7 @@ extern NSString *const SDWebImageErrorDomain; @@ -107,7 +107,7 @@ extern NSString *const SDWebImageErrorDomain;
107 } 107 }
108 108
109 #define dispatch_main_async_safe(block)\ 109 #define dispatch_main_async_safe(block)\
110 - if ([NSThread isMainThread]) {\ 110 + if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\
111 block();\ 111 block();\
112 } else {\ 112 } else {\
113 dispatch_async(dispatch_get_main_queue(), block);\ 113 dispatch_async(dispatch_get_main_queue(), block);\