美文网首页
GPUImage GCD

GPUImage GCD

作者: 老猫_2017 | 来源:发表于2020-01-21 14:29 被阅读0次
    // set queue attribute
    dispatch_queue_attr_t GPUImageDefaultQueueAttribute(void)
    {
    #if TARGET_OS_IPHONE
        if ([[[UIDevice currentDevice] systemVersion] compare:@"9.0" options:NSNumericSearch] != NSOrderedAscending)
        {
            return dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0);
        }
    #endif
        return nil;
    }
    
    // create queu with attribute  serial  queue
    _contextQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.openGLESContextQueue", GPUImageDefaultQueueAttribute());
    
    // set specific
    dispatch_queue_set_specific(_contextQueue, openGLESContextQueueKey, (__bridge void *)self, NULL);
    
    
    // camera - global queue
    cameraProcessingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
    
    // audio global queue   
    audioProcessingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0);
    
    // semaphore 信号量    
    frameRenderingSemaphore = dispatch_semaphore_create(1);
    // 每次保证只能有一个资源执行 
    if (dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_NOW) != 0) {
      ...
    }
    
    // 完成之后,释放资源            
    dispatch_semaphore_signal(frameRenderingSemaphore);
    
    
    // create 0
        imageUpdateSemaphore = dispatch_semaphore_create(0);
    
    //  signal +1
        dispatch_semaphore_signal(imageUpdateSemaphore);
    //  -1
    dispatch_semaphore_wait(imageUpdateSemaphore, TIME);
    
    

    总结:主要用信号量进行资源的控制访问,保证,只有一共在访问它.

    创建队列的时候,指定其 队列优先级

    特定队列访问资源, dispatch_queue_set_specific 来进行获取设定队列

    相关文章

      网友评论

          本文标题:GPUImage GCD

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