From f060310ffe6a3dcc99237eb3aed18e9b59f1fd5f Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 31 Mar 2019 15:53:33 +0800 Subject: [PATCH] Remove the previous using atomic property, use lock instead. --- SDWebImage/SDImageCachesManager.h | 2 +- SDWebImage/SDImageCachesManager.m | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/SDWebImage/SDImageCachesManager.h b/SDWebImage/SDImageCachesManager.h index 41e5b046..2c0d7b03 100644 --- a/SDWebImage/SDImageCachesManager.h +++ b/SDWebImage/SDImageCachesManager.h @@ -58,7 +58,7 @@ typedef NS_ENUM(NSUInteger, SDImageCachesManagerOperationPolicy) { /** All caches in caches manager. The caches array is a priority queue, which means the later added cache will have the highest priority */ -@property (atomic, copy, readwrite, nullable) NSArray> *caches; +@property (nonatomic, copy, readwrite, nullable) NSArray> *caches; /** Add a new cache to the end of caches array. Which has the highest priority. diff --git a/SDWebImage/SDImageCachesManager.m b/SDWebImage/SDImageCachesManager.m index b02f3f55..1ef33e85 100644 --- a/SDWebImage/SDImageCachesManager.m +++ b/SDWebImage/SDImageCachesManager.m @@ -75,7 +75,9 @@ if (!key) { return nil; } - NSArray> *caches = [self.caches copy]; + SD_LOCK(self.cachesLock); + NSArray> *caches = self.caches; + SD_UNLOCK(self.cachesLock); NSUInteger count = caches.count; if (count == 0) { return nil; @@ -117,7 +119,9 @@ if (!key) { return; } - NSArray> *caches = [self.caches copy]; + SD_LOCK(self.cachesLock); + NSArray> *caches = self.caches; + SD_UNLOCK(self.cachesLock); NSUInteger count = caches.count; if (count == 0) { return; @@ -155,7 +159,9 @@ if (!key) { return; } - NSArray> *caches = [self.caches copy]; + SD_LOCK(self.cachesLock); + NSArray> *caches = self.caches; + SD_UNLOCK(self.cachesLock); NSUInteger count = caches.count; if (count == 0) { return; @@ -193,7 +199,9 @@ if (!key) { return; } - NSArray> *caches = [self.caches copy]; + SD_LOCK(self.cachesLock); + NSArray> *caches = self.caches; + SD_UNLOCK(self.cachesLock); NSUInteger count = caches.count; if (count == 0) { return; @@ -230,7 +238,9 @@ } - (void)clearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock { - NSArray> *caches = [self.caches copy]; + SD_LOCK(self.cachesLock); + NSArray> *caches = self.caches; + SD_UNLOCK(self.cachesLock); NSUInteger count = caches.count; if (count == 0) { return;