Skip to content

dispatch_set_target_queue usage not correct #52

@haifenghuang

Description

@haifenghuang

In initWithCacheDirectory method of EGOCache.m file, the dispatch_set_target_queue's usage is not correct.

- (instancetype)initWithCacheDirectory:(NSString*)cacheDirectory {
    if((self = [super init])) {
        _cacheInfoQueue = dispatch_queue_create("com.enormego.egocache.info", DISPATCH_QUEUE_SERIAL);
        dispatch_queue_t priority = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_set_target_queue(priority, _cacheInfoQueue);

        _frozenCacheInfoQueue = dispatch_queue_create("com.enormego.egocache.info.frozen", DISPATCH_QUEUE_SERIAL);
        priority = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_set_target_queue(priority, _frozenCacheInfoQueue);

        _diskQueue = dispatch_queue_create("com.enormego.egocache.disk", DISPATCH_QUEUE_CONCURRENT);
        priority = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
        dispatch_set_target_queue(priority, _diskQueue);

In man page of dispatch_set_target_queue, it has below statements:

The result of passing the main queue or a global concurrent queue as the first argument of dispatch_set_target_queue() is undefined.

So the usage of dispatch_set_target_queue is not correct, the correct usage should be as below:

dispatch_set_target_queue(_cacheInfoQueue, priority);
dispatch_set_target_queue(_frozenCacheInfoQueue, priority);
dispatch_set_target_queue(_diskQueue, priority);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions