Created
May 10, 2016 13:34
-
-
Save xtinger/7f9981bcb4f213c7897f66847daf6f18 to your computer and use it in GitHub Desktop.
dispatch_once_on_main_thread
This file contains 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
void dispatch_once_on_main_thread(dispatch_once_t *predicate, | |
dispatch_block_t block) { | |
if ([NSThread isMainThread]) { | |
dispatch_once(predicate, block); | |
} else { | |
if (DISPATCH_EXPECT(*predicate == 0L, NO)) { | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
dispatch_once(predicate, block); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment