-_bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- if (bufmgr->backend->bo_unlock)
- bufmgr->backend->bo_unlock(bo);
-}
-
-static int
-_tbm_bo_lock(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = NULL;
- int old;
- int ret = 0;
-
- if (!bo)
- return 0;
-
- bufmgr = bo->bufmgr;
-
- /* do not try to lock the bo */
- if (bufmgr->lock_type == LOCK_TRY_NEVER)
- return 1;
-
- if (bo->lock_cnt < 0) {
- TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
- bo, bo->lock_cnt);
- }
-
- old = bo->lock_cnt;
- if (bufmgr->lock_type == LOCK_TRY_ONCE) {
- if (bo->lock_cnt == 0) {
- pthread_mutex_unlock(&bufmgr->lock);
- ret = _bo_lock(bo, device, opt);
- pthread_mutex_lock(&bufmgr->lock);
- if (ret)
- bo->lock_cnt++;
- } else
- ret = 1;
- } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) {
- pthread_mutex_unlock(&bufmgr->lock);
- ret = _bo_lock(bo, device, opt);
- pthread_mutex_lock(&bufmgr->lock);
- if (ret)
- bo->lock_cnt++;
- } else {
- TBM_LOG_E("error bo:%p lock_type is wrong.\n",
- bo);
- }
-
- DBG_LOCK(">> LOCK bo:%p(%d->%d)\n",
- bo, old, bo->lock_cnt);
-
- return ret;
-}
-
-static void
-_tbm_bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = NULL;
-
- int old;
-
- if (!bo)
- return;
-
- bufmgr = bo->bufmgr;
-
- /* do not try to unlock the bo */
- if (bufmgr->lock_type == LOCK_TRY_NEVER)
- return;
-
- old = bo->lock_cnt;
- if (bufmgr->lock_type == LOCK_TRY_ONCE) {
- if (bo->lock_cnt > 0) {
- bo->lock_cnt--;
- if (bo->lock_cnt == 0)
- _bo_unlock(bo);
- }
- } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) {
- if (bo->lock_cnt > 0) {
- bo->lock_cnt--;
- _bo_unlock(bo);
- }
- } else {
- TBM_LOG_E("error bo:%p lock_type is wrong.\n",
- bo);
- }
-
- if (bo->lock_cnt < 0)
- bo->lock_cnt = 0;
-
- DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n",
- bo, old, bo->lock_cnt);
-}
-
-static int
-_tbm_bo_is_valid(tbm_bo bo)
-{
- tbm_bo old_data = NULL, tmp = NULL;
-
- if (bo == NULL)
- return 0;
-
- if (!LIST_IS_EMPTY(&gBufMgr->bo_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &gBufMgr->bo_list, item_link) {
- if (old_data == bo)
- return 1;
- }
-
- }
- return 0;
-}
-
-static void
-_tbm_bo_ref(tbm_bo bo)
-{
- bo->ref_cnt++;
-}
-
-static void
-_tbm_bo_unref(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- tbm_user_data *old_data = NULL, *tmp = NULL;
-
- if (bo->ref_cnt <= 0)
- return;
-
- bo->ref_cnt--;
- if (bo->ref_cnt == 0) {
- /* destory the user_data_list */
- if (!LIST_IS_EMPTY(&bo->user_data_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &bo->user_data_list, item_link) {
- DBG("free user_data\n");
- user_data_delete(old_data);
- }
- }
-
- if (bo->lock_cnt > 0) {
- TBM_LOG_E("error lock_cnt:%d\n",
- bo->lock_cnt);
- _bo_unlock(bo);
- }
-
- /* call the bo_free */
- bufmgr->backend->bo_free(bo);
- bo->priv = NULL;
-
- LIST_DEL(&bo->item_link);
- free(bo);
- bo = NULL;
-
- bufmgr->bo_cnt--;
- }
-
-}
-
-/* LCOV_EXCL_START */
-static int
-_check_version(TBMModuleVersionInfo *data)
-{
- int abimaj, abimin;
- int vermaj, vermin;
-
- abimaj = GET_ABI_MAJOR(data->abiversion);
- abimin = GET_ABI_MINOR(data->abiversion);
-
- DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
- data->modname ? data->modname : "UNKNOWN!",
- data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
-
- vermaj = GET_ABI_MAJOR(TBM_ABI_VERSION);
- vermin = GET_ABI_MINOR(TBM_ABI_VERSION);
-
- DBG("TBM ABI version %d.%d\n",
- vermaj, vermin);
-
- if (abimaj != vermaj) {
- TBM_LOG_E("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
- abimaj, vermaj);
- return 0;
- } else if (abimin > vermin) {
- TBM_LOG_E("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
- abimin, vermin);
- return 0;
- }
- return 1;
-}
-
-static int
-_tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)