Instead of defining `LOCK` and `UNLOCK` macros in each file, moved them to the `SDWebImageCompat.h`. Also, split into `LOCK` and `LOCKBLOCK`
This commit is contained in:
parent
0108475578
commit
f8fe886334
|
@ -12,10 +12,6 @@
|
||||||
#import "SDImageCodersManager.h"
|
#import "SDImageCodersManager.h"
|
||||||
#import "SDImageFrame.h"
|
#import "SDImageFrame.h"
|
||||||
|
|
||||||
#define LOCK(...) dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER); \
|
|
||||||
__VA_ARGS__; \
|
|
||||||
dispatch_semaphore_signal(self->_lock);
|
|
||||||
|
|
||||||
static CGFloat SDImageScaleFromPath(NSString *string) {
|
static CGFloat SDImageScaleFromPath(NSString *string) {
|
||||||
if (string.length == 0 || [string hasSuffix:@"/"]) return 1;
|
if (string.length == 0 || [string hasSuffix:@"/"]) return 1;
|
||||||
NSString *name = string.stringByDeletingPathExtension;
|
NSString *name = string.stringByDeletingPathExtension;
|
||||||
|
@ -108,7 +104,7 @@ static NSArray *SDBundlePreferredScales() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning:(NSNotification *)notification {
|
- (void)didReceiveMemoryWarning:(NSNotification *)notification {
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
[self.imageTable removeAllObjects];
|
[self.imageTable removeAllObjects];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -178,7 +174,7 @@ static NSArray *SDBundlePreferredScales() {
|
||||||
- (UIImage *)imageForName:(NSString *)name {
|
- (UIImage *)imageForName:(NSString *)name {
|
||||||
NSParameterAssert(name);
|
NSParameterAssert(name);
|
||||||
UIImage *image;
|
UIImage *image;
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
image = [self.imageTable objectForKey:name];
|
image = [self.imageTable objectForKey:name];
|
||||||
});
|
});
|
||||||
return image;
|
return image;
|
||||||
|
@ -187,7 +183,7 @@ static NSArray *SDBundlePreferredScales() {
|
||||||
- (void)storeImage:(UIImage *)image forName:(NSString *)name {
|
- (void)storeImage:(UIImage *)image forName:(NSString *)name {
|
||||||
NSParameterAssert(image);
|
NSParameterAssert(image);
|
||||||
NSParameterAssert(name);
|
NSParameterAssert(name);
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
[self.imageTable setObject:image forKey:name];
|
[self.imageTable setObject:image forKey:name];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,6 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
return vm_stat.free_count * page_size;
|
return vm_stat.free_count * page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOCK(...) dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER); \
|
|
||||||
__VA_ARGS__; \
|
|
||||||
dispatch_semaphore_signal(self->_lock);
|
|
||||||
|
|
||||||
@interface SDWeakProxy : NSProxy
|
@interface SDWeakProxy : NSProxy
|
||||||
|
|
||||||
@property (nonatomic, weak, readonly) id target;
|
@property (nonatomic, weak, readonly) id target;
|
||||||
|
@ -242,7 +238,7 @@ dispatch_semaphore_signal(self->_lock);
|
||||||
self.animatedImageScale = 1;
|
self.animatedImageScale = 1;
|
||||||
[_fetchQueue cancelAllOperations];
|
[_fetchQueue cancelAllOperations];
|
||||||
_fetchQueue = nil;
|
_fetchQueue = nil;
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
[_frameBuffer removeAllObjects];
|
[_frameBuffer removeAllObjects];
|
||||||
_frameBuffer = nil;
|
_frameBuffer = nil;
|
||||||
});
|
});
|
||||||
|
@ -303,7 +299,7 @@ dispatch_semaphore_signal(self->_lock);
|
||||||
self.animatedImageScale = image.scale;
|
self.animatedImageScale = image.scale;
|
||||||
if (!self.isProgressive) {
|
if (!self.isProgressive) {
|
||||||
self.currentFrame = image;
|
self.currentFrame = image;
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
self.frameBuffer[@(self.currentFrameIndex)] = self.currentFrame;
|
self.frameBuffer[@(self.currentFrameIndex)] = self.currentFrame;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -424,7 +420,7 @@ dispatch_semaphore_signal(self->_lock);
|
||||||
[_fetchQueue cancelAllOperations];
|
[_fetchQueue cancelAllOperations];
|
||||||
[_fetchQueue addOperationWithBlock:^{
|
[_fetchQueue addOperationWithBlock:^{
|
||||||
NSNumber *currentFrameIndex = @(self.currentFrameIndex);
|
NSNumber *currentFrameIndex = @(self.currentFrameIndex);
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
NSArray *keys = self.frameBuffer.allKeys;
|
NSArray *keys = self.frameBuffer.allKeys;
|
||||||
// only keep the next frame for later rendering
|
// only keep the next frame for later rendering
|
||||||
for (NSNumber * key in keys) {
|
for (NSNumber * key in keys) {
|
||||||
|
@ -681,12 +677,12 @@ dispatch_semaphore_signal(self->_lock);
|
||||||
|
|
||||||
// Update the current frame
|
// Update the current frame
|
||||||
UIImage *currentFrame;
|
UIImage *currentFrame;
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
currentFrame = self.frameBuffer[@(currentFrameIndex)];
|
currentFrame = self.frameBuffer[@(currentFrameIndex)];
|
||||||
});
|
});
|
||||||
BOOL bufferFull = NO;
|
BOOL bufferFull = NO;
|
||||||
if (currentFrame) {
|
if (currentFrame) {
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
// Remove the frame buffer if need
|
// Remove the frame buffer if need
|
||||||
if (self.frameBuffer.count > self.maxBufferCount) {
|
if (self.frameBuffer.count > self.maxBufferCount) {
|
||||||
self.frameBuffer[@(currentFrameIndex)] = nil;
|
self.frameBuffer[@(currentFrameIndex)] = nil;
|
||||||
|
@ -710,7 +706,7 @@ dispatch_semaphore_signal(self->_lock);
|
||||||
if (self.isProgressive) {
|
if (self.isProgressive) {
|
||||||
// Recovery the current frame index and removed frame buffer (See above)
|
// Recovery the current frame index and removed frame buffer (See above)
|
||||||
self.currentFrameIndex = currentFrameIndex;
|
self.currentFrameIndex = currentFrameIndex;
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
self.frameBuffer[@(currentFrameIndex)] = self.currentFrame;
|
self.frameBuffer[@(currentFrameIndex)] = self.currentFrame;
|
||||||
});
|
});
|
||||||
[self stopAnimating];
|
[self stopAnimating];
|
||||||
|
@ -740,7 +736,7 @@ dispatch_semaphore_signal(self->_lock);
|
||||||
UIImage<SDAnimatedImage> *animatedImage = self.animatedImage;
|
UIImage<SDAnimatedImage> *animatedImage = self.animatedImage;
|
||||||
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
|
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
UIImage *fetchFrame = [animatedImage animatedImageFrameAtIndex:fetchFrameIndex];
|
UIImage *fetchFrame = [animatedImage animatedImageFrameAtIndex:fetchFrameIndex];
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
self.frameBuffer[@(fetchFrameIndex)] = fetchFrame;
|
self.frameBuffer[@(fetchFrameIndex)] = fetchFrame;
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -14,9 +14,6 @@
|
||||||
#import "SDImageWebPCoder.h"
|
#import "SDImageWebPCoder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
||||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
|
||||||
|
|
||||||
@interface SDImageCodersManager ()
|
@interface SDImageCodersManager ()
|
||||||
|
|
||||||
@property (nonatomic, strong, nonnull) dispatch_semaphore_t codersLock;
|
@property (nonatomic, strong, nonnull) dispatch_semaphore_t codersLock;
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
#import "SDImageLoadersManager.h"
|
#import "SDImageLoadersManager.h"
|
||||||
#import "SDWebImageDownloader.h"
|
#import "SDWebImageDownloader.h"
|
||||||
|
|
||||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
||||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
|
||||||
|
|
||||||
@interface SDImageLoadersManager ()
|
@interface SDImageLoadersManager ()
|
||||||
|
|
||||||
@property (nonatomic, strong, nonnull) dispatch_semaphore_t loadersLock;
|
@property (nonatomic, strong, nonnull) dispatch_semaphore_t loadersLock;
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
#import "SDMemoryCache.h"
|
#import "SDMemoryCache.h"
|
||||||
#import "SDImageCacheConfig.h"
|
#import "SDImageCacheConfig.h"
|
||||||
|
|
||||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
||||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
|
||||||
|
|
||||||
NSUInteger SDMemoryCacheCostForImage(UIImage * _Nullable image) {
|
NSUInteger SDMemoryCacheCostForImage(UIImage * _Nullable image) {
|
||||||
#if SD_MAC
|
#if SD_MAC
|
||||||
return image.size.height * image.size.width;
|
return image.size.height * image.size.width;
|
||||||
|
|
|
@ -93,3 +93,17 @@
|
||||||
dispatch_async(dispatch_get_main_queue(), block);\
|
dispatch_async(dispatch_get_main_queue(), block);\
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOCK
|
||||||
|
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNLOCK
|
||||||
|
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOCKBLOCK
|
||||||
|
#define LOCKBLOCK(...) dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER); \
|
||||||
|
__VA_ARGS__; \
|
||||||
|
dispatch_semaphore_signal(self->_lock);
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,9 +13,6 @@
|
||||||
|
|
||||||
static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
||||||
|
|
||||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
||||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
|
||||||
|
|
||||||
@interface SDWebImageDownloadToken ()
|
@interface SDWebImageDownloadToken ()
|
||||||
|
|
||||||
@property (nonatomic, strong, nullable, readwrite) NSURL *url;
|
@property (nonatomic, strong, nullable, readwrite) NSURL *url;
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
#import "SDWebImageDownloaderOperation.h"
|
#import "SDWebImageDownloaderOperation.h"
|
||||||
#import "SDWebImageError.h"
|
#import "SDWebImageError.h"
|
||||||
|
|
||||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
||||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
|
||||||
|
|
||||||
// iOS 8 Foundation.framework extern these symbol but the define is in CFNetwork.framework. We just fix this without import CFNetwork.framework
|
// iOS 8 Foundation.framework extern these symbol but the define is in CFNetwork.framework. We just fix this without import CFNetwork.framework
|
||||||
#if (__IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
|
#if (__IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
|
||||||
const float NSURLSessionTaskPriorityHigh = 0.75;
|
const float NSURLSessionTaskPriorityHigh = 0.75;
|
||||||
|
|
|
@ -12,9 +12,6 @@
|
||||||
#import "UIImage+Metadata.h"
|
#import "UIImage+Metadata.h"
|
||||||
#import "SDWebImageError.h"
|
#import "SDWebImageError.h"
|
||||||
|
|
||||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
||||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
|
||||||
|
|
||||||
static id<SDImageCache> _defaultImageCache;
|
static id<SDImageCache> _defaultImageCache;
|
||||||
static id<SDImageLoader> _defaultImageLoader;
|
static id<SDImageLoader> _defaultImageLoader;
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,6 @@
|
||||||
#endif
|
#endif
|
||||||
#import <Accelerate/Accelerate.h>
|
#import <Accelerate/Accelerate.h>
|
||||||
|
|
||||||
#define LOCK(...) dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER); \
|
|
||||||
__VA_ARGS__; \
|
|
||||||
dispatch_semaphore_signal(self->_lock);
|
|
||||||
|
|
||||||
@interface SDWebPCoderFrame : NSObject
|
@interface SDWebPCoderFrame : NSObject
|
||||||
|
|
||||||
@property (nonatomic, assign) NSUInteger index; // Frame index (zero based)
|
@property (nonatomic, assign) NSUInteger index; // Frame index (zero based)
|
||||||
|
@ -741,7 +737,7 @@ static void FreeImageData(void *info, const void *data, size_t size) {
|
||||||
if (index >= _frameCount) {
|
if (index >= _frameCount) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
LOCK({
|
LOCKBLOCK({
|
||||||
image = [self safeAnimatedImageFrameAtIndex:index];
|
image = [self safeAnimatedImageFrameAtIndex:index];
|
||||||
});
|
});
|
||||||
return image;
|
return image;
|
||||||
|
|
Loading…
Reference in New Issue