{
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);
}
网友评论