return 0;
}
+static void
+_tbm_bo_free(tbm_bo bo)
+{
+ tbm_bufmgr bufmgr = bo->bufmgr;
+
+ /* destory the user_data_list */
+ if (!LIST_IS_EMPTY(&bo->user_data_list)) {
+ tbm_user_data *old_data = NULL, *tmp;
+
+ LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
+ &bo->user_data_list, item_link) {
+ TBM_DBG("free user_data\n");
+ user_data_delete(old_data);
+ }
+ }
+
+ while (bo->lock_cnt > 0) {
+ TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
+ _bo_unlock(bo);
+ bo->lock_cnt--;
+ }
+
+ /* call the bo_free */
+ bufmgr->backend->bo_free(bo);
+ bo->priv = NULL;
+
+ LIST_DEL(&bo->item_link);
+ free(bo);
+
+ bufmgr->bo_cnt--;
+}
+
/* LCOV_EXCL_START */
static int
_check_version(TBMModuleVersionInfo *data)
{
TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
+ _tbm_bufmgr_mutex_lock();
pthread_mutex_lock(&gLock);
if (!gBufMgr) {
TBM_LOG_E("gBufmgr already destroy: bufmgr:%p\n", bufmgr);
pthread_mutex_unlock(&gLock);
+ _tbm_bufmgr_mutex_unlock();
return;
}
if (bufmgr->ref_count > 0) {
TBM_TRACE("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
pthread_mutex_unlock(&gLock);
+ _tbm_bufmgr_mutex_unlock();
return;
}
LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bo_list, item_link) {
TBM_LOG_E("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt);
- bo->ref_cnt = 1;
- tbm_bo_unref(bo);
+ _tbm_bo_free(bo);
}
}
gBufMgr = NULL;
pthread_mutex_unlock(&gLock);
+ _tbm_bufmgr_mutex_unlock();
}
int
}
bo->ref_cnt--;
- if (bo->ref_cnt == 0) {
- /* destory the user_data_list */
- if (!LIST_IS_EMPTY(&bo->user_data_list)) {
- tbm_user_data *old_data = NULL, *tmp;
-
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp,
- &bo->user_data_list, item_link) {
- TBM_DBG("free user_data\n");
- user_data_delete(old_data);
- }
- }
-
- while (bo->lock_cnt > 0) {
- TBM_LOG_E("error lock_cnt:%d\n", bo->lock_cnt);
- _bo_unlock(bo);
- bo->lock_cnt--;
- }
-
- /* call the bo_free */
- bufmgr->backend->bo_free(bo);
- bo->priv = NULL;
-
- LIST_DEL(&bo->item_link);
- free(bo);
-
- bufmgr->bo_cnt--;
- }
+ if (bo->ref_cnt == 0)
+ _tbm_bo_free(bo);
_tbm_bufmgr_mutex_unlock();
}