Check queue equality only when queue specific is available

This commit is contained in:
DreamPiggy 2023-05-05 18:46:37 +08:00
parent 4ffd068762
commit 17b5a1d9ab
1 changed files with 10 additions and 8 deletions

View File

@ -32,16 +32,18 @@ static void SDSafeExecute(dispatch_queue_t _Nonnull queue, dispatch_block_t _Non
}
// Check specific to detect queue equal
void *specific = dispatch_queue_get_specific(queue, SDCallbackQueueKey);
void *currentSpecific = dispatch_get_specific(SDCallbackQueueKey);
if (specific && currentSpecific && CFGetTypeID(specific) == CFUUIDGetTypeID() && CFGetTypeID(currentSpecific) == CFUUIDGetTypeID() && CFEqual(specific, currentSpecific)) {
block();
} else {
if (async) {
dispatch_async(queue, block);
} else {
dispatch_sync(queue, block);
if (specific && CFGetTypeID(specific) == CFUUIDGetTypeID()) {
void *currentSpecific = dispatch_get_specific(SDCallbackQueueKey);
if (currentSpecific && CFGetTypeID(currentSpecific) == CFUUIDGetTypeID() && CFEqual(specific, currentSpecific)) {
block();
return;
}
}
if (async) {
dispatch_async(queue, block);
} else {
dispatch_sync(queue, block);
}
}
@implementation SDCallbackQueue