tbm_bufmgr: wrap tbm_bufmgr_deinit to bufmgr mutex 27/134827/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 20 Jun 2017 05:50:52 +0000 (14:50 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Tue, 20 Jun 2017 07:27:43 +0000 (16:27 +0900)
Change-Id: Ibc06e861d75978221c745d8cf393b511115d7603

src/tbm_bufmgr.c

index f101e73..1c7449d 100644 (file)
@@ -453,6 +453,38 @@ _tbm_bo_is_valid(tbm_bo bo)
        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)
@@ -716,11 +748,13 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
 {
        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;
        }
 
@@ -728,6 +762,7 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
        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;
        }
 
@@ -737,8 +772,7 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
 
                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);
                }
        }
 
@@ -769,6 +803,7 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
        gBufMgr = NULL;
 
        pthread_mutex_unlock(&gLock);
+       _tbm_bufmgr_mutex_unlock();
 }
 
 int
@@ -826,33 +861,8 @@ tbm_bo_unref(tbm_bo bo)
        }
 
        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();
 }