tbm_bufmgr: lock/unlock tbm_bufmgr_mutex at tbm_bufmgr function 19/260319/1
authorSooChan Lim <sc1.lim@samsung.com>
Wed, 23 Jun 2021 05:16:52 +0000 (14:16 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 23 Jun 2021 07:14:05 +0000 (16:14 +0900)
move the lock/unlock code from tbm_bo_alloc to
tbm_bufmgr_internal_alloc_bo

Change-Id: Ic4ac270049b30a3859784363d56961a080de53c9

src/tbm_bo.c
src/tbm_bufmgr.c
src/tbm_bufmgr_int.h

index 42552fb..1987327 100644 (file)
@@ -304,29 +304,15 @@ tbm_bo
 tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
 {
        tbm_bo bo;
-       tbm_error_e error;
-
-       _tbm_bufmgr_mutex_lock();
-       _tbm_set_last_result(TBM_ERROR_NONE);
-
-       TBM_BO_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
-       TBM_BO_RETURN_VAL_IF_FAIL(size > 0, NULL);
 
-       bo = tbm_bufmgr_internal_alloc_bo(bufmgr, size, flags, &error);
+       bo = tbm_bufmgr_internal_alloc_bo(bufmgr, size, flags);
        if (!bo) {
                /* LCOV_EXCL_START */
-               TBM_ERR("tbm_bufmgr_internal_alloc_bo failed. error:%d", error);
-               _tbm_set_last_result(error);
-               _tbm_bufmgr_mutex_unlock();
+               TBM_ERR("tbm_bufmgr_internal_alloc_bo failed.");
                return NULL;
                /* LCOV_EXCL_STOP */
        }
 
-       TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)\n", bo, size, bo->ref_cnt,
-                       _tbm_flag_to_str(bo->flags));
-
-       _tbm_bufmgr_mutex_unlock();
-
        return bo;
 }
 
index ee9f004..ac57df7 100644 (file)
@@ -863,10 +863,15 @@ tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo)
 }
 
 tbm_bo
-tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_error_e *error)
+tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags)
 {
+       tbm_error_e error = TBM_ERROR_NONE;
        tbm_bo bo;
-       tbm_bo_data *bo_data;
+
+       _tbm_bufmgr_mutex_lock();
+
+       TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+       TBM_BUFMGR_RETURN_VAL_IF_FAIL(size > 0, NULL);
 
        _tbm_bufmgr_check_bo_cnt(bufmgr);
 
@@ -874,24 +879,38 @@ tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_error_e
        if (!bo) {
                /* LCOV_EXCL_START */
                TBM_ERR("memory allocationc failed.");
-               *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
+               error = TBM_ERROR_OUT_OF_MEMORY;
+               goto failed;
                /* LCOV_EXCL_STOP */
        }
 
-       bo_data = tbm_module_alloc_bo_data(bufmgr->module, bo, size, flags, error);
-       if (!bo_data) {
+       bo->bo_data = tbm_module_alloc_bo_data(bufmgr->module, bo, size, flags, &error);
+       if (!bo->bo_data) {
                /* LCOV_EXCL_START */
-               TBM_ERR("tbm_module_alloc_bo_data failed. size:%d flags:%s error:%d", size, _tbm_flag_to_str(flags), *error);
+               TBM_ERR("tbm_module_alloc_bo_data failed. size:%d flags:%s error:%d", size, _tbm_flag_to_str(flags), error);
                free(bo);
-               return NULL;
+               _tbm_set_last_result(error);
+               _tbm_bufmgr_mutex_unlock();
+               goto failed;
                /* LCOV_EXCL_STOP */
        }
-       bo->bo_data = bo_data;
 
        _tbm_bufmgr_initialize_bo(bufmgr, bo, flags);
 
+       TBM_TRACE_BO("bo(%p) size(%d) refcnt(%d), flag(%s)", bo, size, bo->ref_cnt, _tbm_flag_to_str(bo->flags));
+
+       _tbm_set_last_result(TBM_ERROR_NONE);
+       _tbm_bufmgr_mutex_unlock();
+
        return bo;
+
+/* LCOV_EXCL_START */
+failed:
+       _tbm_set_last_result(error);
+       _tbm_bufmgr_mutex_unlock();
+
+       return NULL;
+/* LCOV_EXCL_STOP */
 }
 
 
index 6c04808..97ae0e5 100644 (file)
@@ -307,7 +307,7 @@ void _tbm_bufmgr_mutex_lock(void);
 void _tbm_bufmgr_mutex_unlock(void);
 tbm_bo tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo);
 
-tbm_bo tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_error_e *error);
+tbm_bo tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags);
 tbm_bo tbm_bufmgr_internal_alloc_bo_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width, int bpp, int height, tbm_bo_memory_type flags, tbm_error_e *error);
 tbm_bo tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_data, int flags, tbm_error_e *error);
 tbm_bo tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, tbm_key key);