From c05668439fdfa73586bf9875c1170a4b3fb8a655 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 23 Jun 2021 13:56:55 +0900 Subject: [PATCH] tbm_bufmgr: lock/unlock tbm_bufmgr_mutex at tbm_bufmgr function move the lock/unlock code from tbm_bo_import_fd to tbm_bufmgr_internal_import_with_fd Change-Id: I9784f421e91ce3da6a702829c67a08be937b1d22 --- src/tbm_bo.c | 17 ++--------------- src/tbm_bufmgr.c | 35 +++++++++++++++++++++++++++-------- src/tbm_bufmgr_int.h | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/tbm_bo.c b/src/tbm_bo.c index 2f47978..42552fb 100644 --- a/src/tbm_bo.c +++ b/src/tbm_bo.c @@ -544,28 +544,15 @@ tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) { 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_fd(bufmgr, fd, &error); + bo = tbm_bufmgr_internal_import_bo_with_fd(bufmgr, fd); if (!bo) { /* LCOV_EXCL_START */ - TBM_ERR("tbm_bufmgr_internal_import_fd failed. error:%d", error); - _tbm_set_last_result(error); - _tbm_bufmgr_mutex_unlock(); + TBM_ERR("tbm_bufmgr_internal_import_fd failed."); return NULL; /* LCOV_EXCL_STOP */ } - TBM_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)\n", - bo, bo->ref_cnt, fd, _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 4e78386..ee9f004 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -1052,28 +1052,32 @@ failed: } tbm_bo -tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e *error) +tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd) { + 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_fd(bufmgr->module, bo, fd, error); + bo->bo_data = tbm_module_import_bo_data_with_fd(bufmgr->module, bo, fd, &error); if (!bo->bo_data) { /* LCOV_EXCL_START */ TBM_ERR("tbm_module_import_bo_data_with_fd failed. tbm_fd:%d", fd); free(bo); - return NULL; + goto failed; /* LCOV_EXCL_STOP */ } @@ -1084,18 +1088,33 @@ tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e bo2, bo2->ref_cnt, fd, _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_TRACE_BO("import bo(%p) ref(%d) fd(%d) flag(%s)", + bo, bo->ref_cnt, fd, _tbm_flag_to_str(bo->flags)); + _tbm_bufmgr_initialize_bo(bufmgr, 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; } /* LCOV_EXCL_STOP */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 5b27571..6c04808 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -311,6 +311,6 @@ tbm_bo tbm_bufmgr_internal_alloc_bo(tbm_bufmgr bufmgr, int size, int flags, tbm_ 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_bo tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd, tbm_error_e *error); +tbm_bo tbm_bufmgr_internal_import_bo_with_fd(tbm_bufmgr bufmgr, tbm_fd fd); #endif /* _TBM_BUFMGR_INT_H_ */ -- 2.7.4