zoukankan      html  css  js  c++  java
  • 1. QCamera2基础组件——cam_semaphore


    /*
    Copyright (c) 2012, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef __QCAMERA_SEMAPHORE_H__ #define __QCAMERA_SEMAPHORE_H__ #ifdef __cplusplus extern "C" { #endif /* Implement semaphore with mutex and conditional variable. * Reason being, POSIX semaphore on Android are not used or * well tested. */

    /*
    * 一个非常简单的信号机制,用于进行线程同步。
    * 从 val 进行同步的信号量,mutex 和 cond 用来实现 同步信号量val 的保护.
    */
    typedef struct { int val; pthread_mutex_t mutex; pthread_cond_t cond; } cam_semaphore_t; static inline void cam_sem_init(cam_semaphore_t *s, int n) { pthread_mutex_init(&(s->mutex), NULL); pthread_cond_init(&(s->cond), NULL); s->val = n; // 通常 n = 0 } static inline void cam_sem_post(cam_semaphore_t *s) { pthread_mutex_lock(&(s->mutex)); s->val++; pthread_cond_signal(&(s->cond)); pthread_mutex_unlock(&(s->mutex)); } static inline int cam_sem_wait(cam_semaphore_t *s) { int rc = 0; pthread_mutex_lock(&(s->mutex)); while (s->val == 0) rc = pthread_cond_wait(&(s->cond), &(s->mutex)); s->val--; pthread_mutex_unlock(&(s->mutex)); return rc; } static inline void cam_sem_destroy(cam_semaphore_t *s) { pthread_mutex_destroy(&(s->mutex)); pthread_cond_destroy(&(s->cond)); s->val = 0; } #ifdef __cplusplus } #endif #endif /* __QCAMERA_SEMAPHORE_H__ */
  • 相关阅读:
    信步漫谈之Redis—集群方案(Linux下搭建Cluster集群)
    信步漫谈之AD域服务器—LDAPS认证改密
    贷款申请数据管理,来,金融精英看过来
    老板说,管理房源以后不准用Excel了!| 数据管理 | 数据搜集
    房地产售楼销售数据管理| 数据上报 | 数据管理 | 数据搜集
    简道云如何实现零售行业抄单管理 | 数据管理
    如何利用简道云实现专柜管理? | 数据管理
    以bug管理为例--教你做简单的项目管理| 数据管理
    订单数据上报 | 数据管理
    终端库存数据上报 | 数据上报
  • 原文地址:https://www.cnblogs.com/ronnydm/p/6961091.html
Copyright © 2011-2022 走看看