Skip to content

Instantly share code, notes, and snippets.

@liuliu
Created December 26, 2019 21:51
Show Gist options
  • Save liuliu/d25450647671e79019f8a01f0c08bd52 to your computer and use it in GitHub Desktop.
Save liuliu/d25450647671e79019f8a01f0c08bd52 to your computer and use it in GitHub Desktop.
static atomic_int executed_count;
void my_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
dispatch_block_t wrapped_block = ^{
++executed_count;
block();
};
struct Block_layout *old_block_layout = (__bridge struct Block_layout *)block;
if (old_block_layout->invoke == dispatch_block_special_invoke()) {
wrapped_block = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, wrapped_block);
struct Block_layout *wrapped_block_layout = (__bridge struct Block_layout *)wrapped_block;
struct dispatch_block_private_data_s *old_dbpds = (struct dispatch_block_private_data_s *)(old_block_layout + 1);
struct dispatch_block_private_data_s *wrapped_dbpds = (struct dispatch_block_private_data_s *)(wrapped_block_layout + 1);
if (old_dbpds->dbpd_magic == 0xD159B10C) {
wrapped_dbpds->dbpd_flags = old_dbpds->dbpd_flags;
wrapped_dbpds->dbpd_priority = old_dbpds->dbpd_priority;
}
}
dispatch_async(queue, wrapped_block);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment