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 "SDImageFrame.h"
|
||||
|
||||
#define LOCK(...) dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER); \
|
||||
__VA_ARGS__; \
|
||||
dispatch_semaphore_signal(self->_lock);
|
||||
|
||||
static CGFloat SDImageScaleFromPath(NSString *string) {
|
||||
if (string.length == 0 || [string hasSuffix:@"/"]) return 1;
|
||||
NSString *name = string.stringByDeletingPathExtension;
|
||||
|
@ -108,7 +104,7 @@ static NSArray *SDBundlePreferredScales() {
|
|||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning:(NSNotification *)notification {
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
[self.imageTable removeAllObjects];
|
||||
});
|
||||
}
|
||||
|
@ -178,7 +174,7 @@ static NSArray *SDBundlePreferredScales() {
|
|||
- (UIImage *)imageForName:(NSString *)name {
|
||||
NSParameterAssert(name);
|
||||
UIImage *image;
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
image = [self.imageTable objectForKey:name];
|
||||
});
|
||||
return image;
|
||||
|
@ -187,7 +183,7 @@ static NSArray *SDBundlePreferredScales() {
|
|||
- (void)storeImage:(UIImage *)image forName:(NSString *)name {
|
||||
NSParameterAssert(image);
|
||||
NSParameterAssert(name);
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
[self.imageTable setObject:image forKey:name];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,10 +38,6 @@ static NSUInteger SDDeviceFreeMemory() {
|
|||
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
|
||||
|
||||
@property (nonatomic, weak, readonly) id target;
|
||||
|
@ -242,7 +238,7 @@ dispatch_semaphore_signal(self->_lock);
|
|||
self.animatedImageScale = 1;
|
||||
[_fetchQueue cancelAllOperations];
|
||||
_fetchQueue = nil;
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
[_frameBuffer removeAllObjects];
|
||||
_frameBuffer = nil;
|
||||
});
|
||||
|
@ -303,7 +299,7 @@ dispatch_semaphore_signal(self->_lock);
|
|||
self.animatedImageScale = image.scale;
|
||||
if (!self.isProgressive) {
|
||||
self.currentFrame = image;
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
self.frameBuffer[@(self.currentFrameIndex)] = self.currentFrame;
|
||||
});
|
||||
}
|
||||
|
@ -424,7 +420,7 @@ dispatch_semaphore_signal(self->_lock);
|
|||
[_fetchQueue cancelAllOperations];
|
||||
[_fetchQueue addOperationWithBlock:^{
|
||||
NSNumber *currentFrameIndex = @(self.currentFrameIndex);
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
NSArray *keys = self.frameBuffer.allKeys;
|
||||
// only keep the next frame for later rendering
|
||||
for (NSNumber * key in keys) {
|
||||
|
@ -681,12 +677,12 @@ dispatch_semaphore_signal(self->_lock);
|
|||
|
||||
// Update the current frame
|
||||
UIImage *currentFrame;
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
currentFrame = self.frameBuffer[@(currentFrameIndex)];
|
||||
});
|
||||
BOOL bufferFull = NO;
|
||||
if (currentFrame) {
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
// Remove the frame buffer if need
|
||||
if (self.frameBuffer.count > self.maxBufferCount) {
|
||||
self.frameBuffer[@(currentFrameIndex)] = nil;
|
||||
|
@ -710,7 +706,7 @@ dispatch_semaphore_signal(self->_lock);
|
|||
if (self.isProgressive) {
|
||||
// Recovery the current frame index and removed frame buffer (See above)
|
||||
self.currentFrameIndex = currentFrameIndex;
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
self.frameBuffer[@(currentFrameIndex)] = self.currentFrame;
|
||||
});
|
||||
[self stopAnimating];
|
||||
|
@ -740,7 +736,7 @@ dispatch_semaphore_signal(self->_lock);
|
|||
UIImage<SDAnimatedImage> *animatedImage = self.animatedImage;
|
||||
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
|
||||
UIImage *fetchFrame = [animatedImage animatedImageFrameAtIndex:fetchFrameIndex];
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
self.frameBuffer[@(fetchFrameIndex)] = fetchFrame;
|
||||
});
|
||||
}];
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
#import "SDImageWebPCoder.h"
|
||||
#endif
|
||||
|
||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||
|
||||
@interface SDImageCodersManager ()
|
||||
|
||||
@property (nonatomic, strong, nonnull) dispatch_semaphore_t codersLock;
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
#import "SDImageLoadersManager.h"
|
||||
#import "SDWebImageDownloader.h"
|
||||
|
||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||
|
||||
@interface SDImageLoadersManager ()
|
||||
|
||||
@property (nonatomic, strong, nonnull) dispatch_semaphore_t loadersLock;
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
#import "SDMemoryCache.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) {
|
||||
#if SD_MAC
|
||||
return image.size.height * image.size.width;
|
||||
|
|
|
@ -93,3 +93,17 @@
|
|||
dispatch_async(dispatch_get_main_queue(), block);\
|
||||
}
|
||||
#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;
|
||||
|
||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||
|
||||
@interface SDWebImageDownloadToken ()
|
||||
|
||||
@property (nonatomic, strong, nullable, readwrite) NSURL *url;
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
#import "SDWebImageDownloaderOperation.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
|
||||
#if (__IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
|
||||
const float NSURLSessionTaskPriorityHigh = 0.75;
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
#import "UIImage+Metadata.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<SDImageLoader> _defaultImageLoader;
|
||||
|
||||
|
|
|
@ -26,10 +26,6 @@
|
|||
#endif
|
||||
#import <Accelerate/Accelerate.h>
|
||||
|
||||
#define LOCK(...) dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER); \
|
||||
__VA_ARGS__; \
|
||||
dispatch_semaphore_signal(self->_lock);
|
||||
|
||||
@interface SDWebPCoderFrame : NSObject
|
||||
|
||||
@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) {
|
||||
return nil;
|
||||
}
|
||||
LOCK({
|
||||
LOCKBLOCK({
|
||||
image = [self safeAnimatedImageFrameAtIndex:index];
|
||||
});
|
||||
return image;
|
||||
|
|
Loading…
Reference in New Issue