From: SooChan Lim Date: Wed, 23 Jun 2021 04:10:19 +0000 (+0900) Subject: tbm_bufmgr: lock/unlock tbm_bufmgr_mutex at tbm_bufmgr function X-Git-Tag: accepted/tizen/unified/20210625.170433~14 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Flibtbm.git;a=commitdiff_plain;h=c6c6ffc5dc4d168fbb02d6760d91a4666fb0874b tbm_bufmgr: lock/unlock tbm_bufmgr_mutex at tbm_bufmgr function move the lock/unlock code from tbm_bo_import to tbm_bufmgr_internal_import_with_key Change-Id: I10969db4deea995ab206148f3ea2e3affa030c0e --- diff --git a/src/tbm_bo.c b/src/tbm_bo.c index 8f1261e..658f852 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -528,28 +528,15 @@ tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) { 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); - bo = tbm_bufmgr_internal_import_bo_with_key(bufmgr, key, &error); + bo = tbm_bufmgr_internal_import_bo_with_key(bufmgr, key); if (!bo) { /* LCOV_EXCL_START */ - TBM_ERR("tbm_bufmgr_internal_import_key failed. error:%d", error); - _tbm_set_last_result(error); - _tbm_bufmgr_mutex_unlock(); + TBM_ERR("tbm_bufmgr_internal_import_bo_with_key failed"); return NULL; /* LCOV_EXCL_STOP */ } - TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list\n", - bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags)); - - _tbm_bufmgr_mutex_unlock(); - return bo; } diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index a57980f..4e78386 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -986,28 +986,32 @@ tbm_bufmgr_internal_alloc_bo_with_bo_data(tbm_bufmgr bufmgr, tbm_bo_data *bo_dat } tbm_bo -tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, unsigned int key, tbm_error_e *error) +tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, unsigned int key) { + tbm_error_e error = TBM_ERROR_NONE; tbm_bo bo, bo2; int flags; + _tbm_bufmgr_mutex_lock(); + + TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL); + _tbm_bufmgr_check_bo_cnt(bufmgr); bo = calloc(1, sizeof(struct _tbm_bo)); if (!bo) { /* LCOV_EXCL_START */ TBM_ERR("memory allocationc failed."); - *error = TBM_ERROR_OUT_OF_MEMORY; - return NULL; + goto failed; /* LCOV_EXCL_STOP */ } - bo->bo_data = tbm_module_import_bo_data_with_key(bufmgr->module, bo, key, error); + bo->bo_data = tbm_module_import_bo_data_with_key(bufmgr->module, bo, key, &error); if (!bo->bo_data) { /* LCOV_EXCL_START */ TBM_ERR("tbm_module_import_bo_data_with_key failed. tbm_key:%d", key); free(bo); - return NULL; + goto failed; /* LCOV_EXCL_STOP */ } @@ -1018,18 +1022,33 @@ tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, unsigned int key, tbm_ bo2, bo2->ref_cnt, key, _tbm_flag_to_str(bo2->flags)); bo2->ref_cnt++; free(bo); + _tbm_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); return bo2; } - flags = tbm_bo_data_get_memory_types(bo->bo_data, error); - if (*error != TBM_ERROR_NONE) { - TBM_ERR("fail to get the bo flags(memory_types)"); + flags = tbm_bo_data_get_memory_types(bo->bo_data, &error); + if (error != TBM_ERROR_NONE) { + TBM_WRN("tbm_bo_data_get_memory_types filed. use the default flags:TBM_BO_DEFAULT."); flags = TBM_BO_DEFAULT; + error = TBM_ERROR_NONE; } _tbm_bufmgr_initialize_bo(bufmgr, bo, flags); + TBM_TRACE_BO("import new bo(%p) ref(%d) key(%d) flag(%s) in list", + bo, bo->ref_cnt, key, _tbm_flag_to_str(bo->flags)); + + _tbm_set_last_result(TBM_ERROR_NONE); + _tbm_bufmgr_mutex_unlock(); + return bo; + +failed: + _tbm_set_last_result(error); + _tbm_bufmgr_mutex_unlock(); + + return NULL; } tbm_bo diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index b24a7d9..5b27571 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -310,7 +310,7 @@ 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_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, tbm_error_e *error); +tbm_bo tbm_bufmgr_internal_import_bo_with_key(tbm_bufmgr bufmgr, tbm_key key); tbm_bo tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e *error); #endif /* _TBM_BUFMGR_INT_H_ */