Created
June 3, 2016 09:45
-
-
Save steipete/41cba69f4df6754c111c0cb8c79fea5c to your computer and use it in GitHub Desktop.
Main thread checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PSPDF_EXTERN BOOL PSPDFIsMainThread(void) { | |
// dispatch_get_current_queue is deprecated because most of the time it's not a good idea to call it. | |
// NSThread.isMainThread simply calls pthread_main_np so we can save a bit if we call it directly. | |
PSPDF_DEPRECATED_NOWARN(return pthread_main_np() || dispatch_get_current_queue() == dispatch_get_main_queue();) |
And what do you think about this kind of condition:
dispatch_queue_get_label(dispatch_get_main_queue()) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is my impression this check does no more good than NSThread.isMainThread.
If pthread_main_np returns false, then the second will always be false as well because that queue only runs in the main thread.
on the other hand, If pthread_main_np returns false, the second condition will never run.