# Conflicts:
#	SDWebImage.xcodeproj/project.pbxproj
This commit is contained in:
DreamPiggy 2020-05-06 21:51:03 +08:00
commit 7a430b23b9
8 changed files with 117 additions and 45 deletions

View File

@ -1,3 +1,9 @@
## [5.7.4 - 5.7 Patch, on May 6th, 2020](https://github.com/SDWebImage/SDWebImage/releases/tag/5.7.4)
See [all tickets marked for the 5.7.4 release](https://github.com/SDWebImage/SDWebImage/milestone/71)
### Fixes
- Fix the issue that NSOperation conforms to `SDWebImageOperation` check failed. Fix cancelling prefetcher hung up #2999 #2998
## [5.7.3 - 5.7 Patch, on Apr 21st, 2020](https://github.com/SDWebImage/SDWebImage/releases/tag/5.7.3) ## [5.7.3 - 5.7 Patch, on Apr 21st, 2020](https://github.com/SDWebImage/SDWebImage/releases/tag/5.7.3)
See [all tickets marked for the 5.7.3 release](https://github.com/SDWebImage/SDWebImage/milestone/70) See [all tickets marked for the 5.7.3 release](https://github.com/SDWebImage/SDWebImage/milestone/70)

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'SDWebImage' s.name = 'SDWebImage'
s.version = '5.7.3' s.version = '5.7.4'
s.osx.deployment_target = '10.10' s.osx.deployment_target = '10.10'
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'

View File

@ -115,6 +115,8 @@
327054DC206CD8B3006EA328 /* SDImageAPNGCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */; }; 327054DC206CD8B3006EA328 /* SDImageAPNGCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */; };
3287E6D1244C0C1400007311 /* MKAnnotationView+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3287E6CD244C0C1400007311 /* MKAnnotationView+WebCache.m */; }; 3287E6D1244C0C1400007311 /* MKAnnotationView+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3287E6CD244C0C1400007311 /* MKAnnotationView+WebCache.m */; };
3287E6D2244C0C1400007311 /* MKAnnotationView+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 3287E6CE244C0C1400007311 /* MKAnnotationView+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3287E6D2244C0C1400007311 /* MKAnnotationView+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 3287E6CE244C0C1400007311 /* MKAnnotationView+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
327F2E83245AE1650075F846 /* SDWebImageOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 327F2E82245AE1650075F846 /* SDWebImageOperation.m */; };
327F2E84245AE1650075F846 /* SDWebImageOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 327F2E82245AE1650075F846 /* SDWebImageOperation.m */; };
328BB69E2081FED200760D6C /* SDWebImageCacheKeyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 328BB69E2081FED200760D6C /* SDWebImageCacheKeyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
328BB6A22081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; }; 328BB6A22081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; };
328BB6A42081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; }; 328BB6A42081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; };
@ -441,6 +443,7 @@
327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDImageAPNGCoder.m; path = Core/SDImageAPNGCoder.m; sourceTree = "<group>"; }; 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDImageAPNGCoder.m; path = Core/SDImageAPNGCoder.m; sourceTree = "<group>"; };
3287E6CD244C0C1400007311 /* MKAnnotationView+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MKAnnotationView+WebCache.m"; sourceTree = "<group>"; }; 3287E6CD244C0C1400007311 /* MKAnnotationView+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MKAnnotationView+WebCache.m"; sourceTree = "<group>"; };
3287E6CE244C0C1400007311 /* MKAnnotationView+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MKAnnotationView+WebCache.h"; sourceTree = "<group>"; }; 3287E6CE244C0C1400007311 /* MKAnnotationView+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MKAnnotationView+WebCache.h"; sourceTree = "<group>"; };
327F2E82245AE1650075F846 /* SDWebImageOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDWebImageOperation.m; path = Core/SDWebImageOperation.m; sourceTree = "<group>"; };
328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheKeyFilter.h; path = Core/SDWebImageCacheKeyFilter.h; sourceTree = "<group>"; }; 328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheKeyFilter.h; path = Core/SDWebImageCacheKeyFilter.h; sourceTree = "<group>"; };
328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDWebImageCacheKeyFilter.m; path = Core/SDWebImageCacheKeyFilter.m; sourceTree = "<group>"; }; 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDWebImageCacheKeyFilter.m; path = Core/SDWebImageCacheKeyFilter.m; sourceTree = "<group>"; };
328BB6A82081FEE500760D6C /* SDWebImageCacheSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheSerializer.h; path = Core/SDWebImageCacheSerializer.h; sourceTree = "<group>"; }; 328BB6A82081FEE500760D6C /* SDWebImageCacheSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheSerializer.h; path = Core/SDWebImageCacheSerializer.h; sourceTree = "<group>"; };
@ -857,6 +860,7 @@
320CAE132086F50500CFFC80 /* SDWebImageError.h */, 320CAE132086F50500CFFC80 /* SDWebImageError.h */,
320CAE142086F50500CFFC80 /* SDWebImageError.m */, 320CAE142086F50500CFFC80 /* SDWebImageError.m */,
530E49E71646388E002868E7 /* SDWebImageOperation.h */, 530E49E71646388E002868E7 /* SDWebImageOperation.h */,
327F2E82245AE1650075F846 /* SDWebImageOperation.m */,
324DF4B2200A14DC008A84CC /* SDWebImageDefine.h */, 324DF4B2200A14DC008A84CC /* SDWebImageDefine.h */,
324DF4B3200A14DC008A84CC /* SDWebImageDefine.m */, 324DF4B3200A14DC008A84CC /* SDWebImageDefine.m */,
325312C6200F09910046BF1E /* SDWebImageTransition.h */, 325312C6200F09910046BF1E /* SDWebImageTransition.h */,
@ -1208,6 +1212,7 @@
4A2CAE201AB4BB6C00B6BC39 /* SDImageCache.m in Sources */, 4A2CAE201AB4BB6C00B6BC39 /* SDImageCache.m in Sources */,
4369C2801D9807EC007E863A /* UIView+WebCache.m in Sources */, 4369C2801D9807EC007E863A /* UIView+WebCache.m in Sources */,
329A18611FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */, 329A18611FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */,
327F2E84245AE1650075F846 /* SDWebImageOperation.m in Sources */,
328BB6B22081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */, 328BB6B22081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */,
325C4611223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */, 325C4611223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */,
); );
@ -1282,6 +1287,7 @@
ABBE71A818C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m in Sources */, ABBE71A818C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m in Sources */,
4369C27E1D9807EC007E863A /* UIView+WebCache.m in Sources */, 4369C27E1D9807EC007E863A /* UIView+WebCache.m in Sources */,
329A185F1FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */, 329A185F1FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */,
327F2E83245AE1650075F846 /* SDWebImageOperation.m in Sources */,
328BB6B02081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */, 328BB6B02081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */,
325C4610223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */, 325C4610223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */,
); );

View File

@ -0,0 +1,14 @@
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "SDWebImageOperation.h"
/// NSOperation conform to `SDWebImageOperation`.
@implementation NSOperation (SDWebImageOperation)
@end

View File

@ -20,6 +20,10 @@
atomic_flag _isAllFinished; atomic_flag _isAllFinished;
unsigned long _totalCount; unsigned long _totalCount;
// Used to ensure NSPointerArray thread safe
dispatch_semaphore_t _prefetchOperationsLock;
dispatch_semaphore_t _loadOperationsLock;
} }
@property (nonatomic, copy, readwrite) NSArray<NSURL *> *urls; @property (nonatomic, copy, readwrite) NSArray<NSURL *> *urls;
@ -106,7 +110,6 @@
} }
- (void)startPrefetchWithToken:(SDWebImagePrefetchToken * _Nonnull)token { - (void)startPrefetchWithToken:(SDWebImagePrefetchToken * _Nonnull)token {
NSPointerArray *operations = token.loadOperations;
for (NSURL *url in token.urls) { for (NSURL *url in token.urls) {
@autoreleasepool { @autoreleasepool {
@weakify(self); @weakify(self);
@ -142,13 +145,13 @@
[asyncOperation complete]; [asyncOperation complete];
}]; }];
NSAssert(operation != nil, @"Operation should not be nil, [SDWebImageManager loadImageWithURL:options:context:progress:completed:] break prefetch logic"); NSAssert(operation != nil, @"Operation should not be nil, [SDWebImageManager loadImageWithURL:options:context:progress:completed:] break prefetch logic");
@synchronized (token) { SD_LOCK(token->_loadOperationsLock);
[operations addPointer:(__bridge void *)operation]; [token.loadOperations addPointer:(__bridge void *)operation];
} SD_UNLOCK(token->_loadOperationsLock);
}]; }];
@synchronized (token) { SD_LOCK(token->_prefetchOperationsLock);
[token.prefetchOperations addPointer:(__bridge void *)prefetchOperation]; [token.prefetchOperations addPointer:(__bridge void *)prefetchOperation];
} SD_UNLOCK(token->_prefetchOperationsLock);
[self.prefetchQueue addOperation:prefetchOperation]; [self.prefetchQueue addOperation:prefetchOperation];
} }
} }
@ -262,24 +265,38 @@
@implementation SDWebImagePrefetchToken @implementation SDWebImagePrefetchToken
- (void)cancel { - (instancetype)init {
@synchronized (self) { self = [super init];
[self.prefetchOperations compact]; if (self) {
for (id operation in self.prefetchOperations) { _prefetchOperationsLock = dispatch_semaphore_create(1);
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]) { _loadOperationsLock = dispatch_semaphore_create(1);
[operation cancel];
}
}
self.prefetchOperations.count = 0;
[self.loadOperations compact];
for (id operation in self.loadOperations) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]) {
[operation cancel];
}
}
self.loadOperations.count = 0;
} }
return self;
}
- (void)cancel {
SD_LOCK(_prefetchOperationsLock);
[self.prefetchOperations compact];
for (id operation in self.prefetchOperations) {
id<SDWebImageOperation> strongOperation = operation;
if (strongOperation) {
[strongOperation cancel];
}
}
self.prefetchOperations.count = 0;
SD_UNLOCK(_prefetchOperationsLock);
SD_LOCK(_loadOperationsLock);
[self.loadOperations compact];
for (id operation in self.loadOperations) {
id<SDWebImageOperation> strongOperation = operation;
if (strongOperation) {
[strongOperation cancel];
}
}
self.loadOperations.count = 0;
SD_UNLOCK(_loadOperationsLock);
self.completionBlock = nil; self.completionBlock = nil;
self.progressBlock = nil; self.progressBlock = nil;
[self.prefetcher removeRunningToken:self]; [self.prefetcher removeRunningToken:self];

View File

@ -35,33 +35,58 @@
} }
- (void)start { - (void)start {
if (self.isCancelled) { @synchronized (self) {
return; if (self.isCancelled) {
} self.finished = YES;
return;
[self willChangeValueForKey:@"isExecuting"]; }
self.executing = YES;
[self didChangeValueForKey:@"isExecuting"]; self.finished = NO;
self.executing = YES;
if (self.executionBlock) {
self.executionBlock(self); if (self.executionBlock) {
} else { self.executionBlock(self);
[self complete]; } else {
self.executing = NO;
self.finished = YES;
}
} }
} }
- (void)cancel { - (void)cancel {
[super cancel]; @synchronized (self) {
[self complete]; [super cancel];
if (self.isExecuting) {
self.executing = NO;
self.finished = YES;
}
}
} }
- (void)complete { - (void)complete {
[self willChangeValueForKey:@"isExecuting"]; @synchronized (self) {
if (self.isExecuting) {
self.finished = YES;
self.executing = NO;
}
}
}
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"]; [self willChangeValueForKey:@"isFinished"];
self.executing = NO; _finished = finished;
self.finished = YES;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"]; [self didChangeValueForKey:@"isFinished"];
} }
- (void)setExecuting:(BOOL)executing {
[self willChangeValueForKey:@"isExecuting"];
_executing = executing;
[self didChangeValueForKey:@"isExecuting"];
}
- (BOOL)isConcurrent {
return YES;
}
@end @end

View File

@ -95,6 +95,10 @@
operation = token.downloadOperation; operation = token.downloadOperation;
expect([operation class]).to.equal([SDWebImageTestDownloadOperation class]); expect([operation class]).to.equal([SDWebImageTestDownloadOperation class]);
// Assert the NSOperation conforms to `SDWebImageOperation`
expect([NSOperation.class conformsToProtocol:@protocol(SDWebImageOperation)]).beTruthy();
expect([operation conformsToProtocol:@protocol(SDWebImageOperation)]).beTruthy();
// back to the original value // back to the original value
downloader.config.operationClass = nil; downloader.config.operationClass = nil;
token = [downloader downloadImageWithURL:imageURL3 options:0 progress:nil completed:nil]; token = [downloader downloadImageWithURL:imageURL3 options:0 progress:nil completed:nil];

View File

@ -15,11 +15,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>5.7.3</string> <string>5.7.4</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>5.7.3</string> <string>5.7.4</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>
<string></string> <string></string>
</dict> </dict>