diff --git a/SDWebImage/Core/SDWebImagePrefetcher.m b/SDWebImage/Core/SDWebImagePrefetcher.m index cc6a3e24..b6632fa6 100644 --- a/SDWebImage/Core/SDWebImagePrefetcher.m +++ b/SDWebImage/Core/SDWebImagePrefetcher.m @@ -22,7 +22,7 @@ unsigned long _totalCount; // Used to ensure NSPointerArray thread safe - SD_LOCK_DECLARE(_prefetchOperationsLock) + SD_LOCK_DECLARE(_prefetchOperationsLock); SD_LOCK_DECLARE(_loadOperationsLock); } diff --git a/SDWebImage/Private/SDInternalMacros.h b/SDWebImage/Private/SDInternalMacros.h index 46352db5..8589a74e 100644 --- a/SDWebImage/Private/SDInternalMacros.h +++ b/SDWebImage/Private/SDInternalMacros.h @@ -11,9 +11,15 @@ #import #import "SDmetamacros.h" +#define SD_USE_OS_UNFAIR_LOCK TARGET_OS_MACCATALYST ||\ + (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_10_0) ||\ + (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12) ||\ + (__TV_OS_VERSION_MIN_REQUIRED >= __TVOS_10_0) ||\ + (__WATCH_OS_VERSION_MIN_REQUIRED >= __WATCHOS_3_0) + #ifndef SD_LOCK_DECLARE -#if TARGET_OS_MACCATALYST -#define SD_LOCK_DECLARE(lock) os_unfair_lock lock; +#if SD_USE_OS_UNFAIR_LOCK +#define SD_LOCK_DECLARE(lock) os_unfair_lock lock #else #define SD_LOCK_DECLARE(lock) os_unfair_lock lock API_AVAILABLE(ios(10.0), tvos(10), watchos(3), macos(10.12)); \ OSSpinLock lock##_deprecated; @@ -21,8 +27,8 @@ OSSpinLock lock##_deprecated; #endif #ifndef SD_LOCK_INIT -#if TARGET_OS_MACCATALYST -#define SD_LOCK_INIT(lock) lock = OS_UNFAIR_LOCK_INIT; +#if SD_USE_OS_UNFAIR_LOCK +#define SD_LOCK_INIT(lock) lock = OS_UNFAIR_LOCK_INIT #else #define SD_LOCK_INIT(lock) if (@available(iOS 10, tvOS 10, watchOS 3, macOS 10.12, *)) lock = OS_UNFAIR_LOCK_INIT; \ else lock##_deprecated = OS_SPINLOCK_INIT; @@ -30,8 +36,8 @@ else lock##_deprecated = OS_SPINLOCK_INIT; #endif #ifndef SD_LOCK -#if TARGET_OS_MACCATALYST -#define SD_LOCK(lock) os_unfair_lock_lock(&lock); +#if SD_USE_OS_UNFAIR_LOCK +#define SD_LOCK(lock) os_unfair_lock_lock(&lock) #else #define SD_LOCK(lock) if (@available(iOS 10, tvOS 10, watchOS 3, macOS 10.12, *)) os_unfair_lock_lock(&lock); \ else OSSpinLockLock(&lock##_deprecated); @@ -39,8 +45,8 @@ else OSSpinLockLock(&lock##_deprecated); #endif #ifndef SD_UNLOCK -#if TARGET_OS_MACCATALYST -#define SD_UNLOCK(lock) os_unfair_lock_unlock(&lock); +#if SD_USE_OS_UNFAIR_LOCK +#define SD_UNLOCK(lock) os_unfair_lock_unlock(&lock) #else #define SD_UNLOCK(lock) if (@available(iOS 10, tvOS 10, watchOS 3, macOS 10.12, *)) os_unfair_lock_unlock(&lock); \ else OSSpinLockUnlock(&lock##_deprecated);