美文网首页
iOS 指定某条queue执行代码

iOS 指定某条queue执行代码

作者: LV大树 | 来源:发表于2024-04-08 21:30 被阅读0次
{
    dispatch_queue_t storageQueue;
    void *storageQueueTag;
}

- (void) init {
        storageQueue = dispatch_queue_create(class_getName([self class]), NULL);
    

    storageQueueTag = &storageQueueTag;
    dispatch_queue_set_specific(storageQueue, storageQueueTag, storageQueueTag, NULL);

}
//get
- (BOOL)autoAllowExternalBinaryDataStorage
{
    __block BOOL result = NO;
    
    dispatch_block_t block = ^{ @autoreleasepool {
        result = self->autoAllowExternalBinaryDataStorage;
    }};
    
    if (dispatch_get_specific(storageQueueTag))
        block();
    else
        dispatch_sync(storageQueue, block);
    
    return result;
}

//set
- (void)setAutoAllowExternalBinaryDataStorage:(BOOL)flag
{
    dispatch_block_t block = ^{
        self->autoAllowExternalBinaryDataStorage = flag;
    };
    
    if (dispatch_get_specific(storageQueueTag))
        block();
    else
        dispatch_sync(storageQueue, block); 
}

相关文章

网友评论

      本文标题:iOS 指定某条queue执行代码

      本文链接:https://www.haomeiwen.com/subject/tyvxxjtx.html