SDWebImage GCD

2020-01-21  本文已影响0人  老猫_2017
// check main queue & async excutor on main queue
#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block)\
    if (dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL) == dispatch_queue_get_label(dispatch_get_main_queue())) {\
        block();\
    } else {\
        dispatch_async(dispatch_get_main_queue(), block);\
    }
#endif

// semaphore 的使用,当 lock 使用,定义宏,会更好一点.        
_failedURLsLock = dispatch_semaphore_create(1);

#ifndef SD_LOCK
#define SD_LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
#endif

#ifndef SD_UNLOCK
#define SD_UNLOCK(lock) dispatch_semaphore_signal(lock);
#endif

总结: 判断queue 的方式
dispatch_semaphore Lock 的方式

上一篇 下一篇

猜你喜欢

热点阅读