Merge branch 'feature/additional_dispatch_method' into 'develop'

Add dispatch async on queue.

See merge request BPHV_MIPS/mvm_core!30
This commit is contained in:
Pan, Xinlei (Ryan) 2019-09-12 13:28:52 -04:00
commit 14a06fde09
2 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,7 @@
+ (void)performSyncBlockInBackground:(nonnull void (^)(void))block;
/// Ensures the block is peformed on the same *labeled* dispatch queue. The queue *must* be previously initialized with a unique label.
+ (void)performBlock:(nonnull void (^)(void))block onQueue:(dispatch_queue_t)queue;
+ (void)performSyncBlock:(nonnull void (^)(void))block onQueue:(nonnull dispatch_queue_t)queue;
@end

View File

@ -42,6 +42,16 @@
}
}
+ (void)performBlock:(nonnull void (^)(void))block onQueue:(dispatch_queue_t)queue {
assert(dispatch_queue_get_label(queue) != NULL); // The queue being queried MUST have a label.
const char *currQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
if (!currQueueLabel || strcmp(dispatch_queue_get_label(queue), currQueueLabel) != 0) {
dispatch_async(queue, block);
} else {
block();
}
}
+ (void)performSyncBlock:(nonnull void (^)(void))block onQueue:(dispatch_queue_t)queue {
assert(dispatch_queue_get_label(queue) != NULL); // The queue being queried MUST have a label.
const char *currQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);