Fix the issue because of main queue label hack
This commit is contained in:
parent
43d74211c3
commit
1b086711ae
|
@ -21,11 +21,14 @@ static void SDReleaseBlock(void *context) {
|
|||
}
|
||||
|
||||
static void inline SDSafeExecute(dispatch_queue_t _Nonnull queue, dispatch_block_t _Nonnull block, BOOL async) {
|
||||
// Special handle for main queue, faster
|
||||
const char *currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
|
||||
if (currentLabel && currentLabel == dispatch_queue_get_label(dispatch_get_main_queue())) {
|
||||
block();
|
||||
return;
|
||||
// Special handle for main queue label only (custom queue can have the same label)
|
||||
const char *label = dispatch_queue_get_label(queue);
|
||||
if (label && label == dispatch_queue_get_label(dispatch_get_main_queue())) {
|
||||
const char *currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
|
||||
if (label == currentLabel) {
|
||||
block();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Check specific to detect queue equal
|
||||
void *specific = dispatch_queue_get_specific(queue, SDCallbackQueueKey);
|
||||
|
|
|
@ -660,12 +660,18 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
|
|||
|
||||
SDImageCache *cache = [[SDImageCache alloc] initWithNamespace:@"Concurrent" diskCacheDirectory:@"/" config:config];
|
||||
NSData *pngData = [NSData dataWithContentsOfFile:[self testPNGPath]];
|
||||
[cache queryCacheOperationForKey:@"Key1" done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
|
||||
expect(data).beNil();
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[cache storeImageData:pngData forKey:@"Key1" completion:^{
|
||||
[expectation fulfill];
|
||||
// Added test case for custom queue
|
||||
[SDCallbackQueue.globalQueue async:^{
|
||||
SDWebImageContext *context = @{SDWebImageContextCallbackQueue : SDCallbackQueue.currentQueue};
|
||||
expect(NSThread.isMainThread).beFalsy();
|
||||
[cache queryCacheOperationForKey:@"Key1" options:0 context:context done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
|
||||
expect(data).beNil();
|
||||
expect(NSThread.isMainThread).beFalsy();
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[cache storeImageData:pngData forKey:@"Key1" completion:^{
|
||||
[expectation fulfill];
|
||||
}];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
|
|
Loading…
Reference in New Issue