From f65f0062726934b2868578d6a44172a9c46d6ab2 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 24 Jun 2021 12:29:44 +0900 Subject: [PATCH] tbm_bufmgr: call _tbm_bufmgr_debug_tbm_info_get at _tbm_bufmgr_check_bo_cnt To avoid the deadlock, _tbm_bufmgr_debug_tbm_info_get is added and _tbm_bufmgr_check_bo_cnt uses _tbm_bufmgr_debug_tbm_info_get function. Change-Id: Ia17077144c8973d4d673994d407a669b3dd3496d --- src/tbm_bufmgr.c | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 55f9243..9ad49b4 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -51,6 +51,7 @@ static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER; static double scale_factor = 0; void _tbm_bufmgr_mutex_unlock(void); +static char *_tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, tbm_error_e *error); //#define TBM_BUFMGR_INIT_TIME @@ -90,11 +91,18 @@ static void _tbm_bufmgr_check_bo_cnt(tbm_bufmgr bufmgr) { static int last_chk_bo_cnt = 0; + char * str; + tbm_error_e error = TBM_ERROR_NONE; if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) && (bufmgr->bo_cnt > last_chk_bo_cnt)) { TBM_DBG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt); - tbm_bufmgr_debug_show(bufmgr); + str = _tbm_bufmgr_debug_tbm_info_get(bufmgr, &error); + if (str) { + TBM_DBG(" %s", str); + free(str); + } + last_chk_bo_cnt = bufmgr->bo_cnt; } } @@ -438,8 +446,8 @@ tbm_bufmgr_get_capability(tbm_bufmgr bufmgr) } /* LCOV_EXCL_START */ -char * -tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) +static char * +_tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, tbm_error_e *error) { char app_name[255] = {0,}, title[512] = {0,}; tbm_surface_debug_data *debug_old_data = NULL; @@ -447,24 +455,18 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) int len = 1024*4; int c = 0; int size; - tbm_error_e error; long pid = 0; - pthread_mutex_lock(&gLock); - _tbm_set_last_result(TBM_ERROR_NONE); - if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) { TBM_ERR("invalid bufmgr\n"); - _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER); - pthread_mutex_unlock(&gLock); + *error = TBM_ERROR_INVALID_PARAMETER; return NULL; } str = malloc(len); if (!str) { TBM_ERR("Fail to allocate the string.\n"); - _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY); - pthread_mutex_unlock(&gLock); + *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; } @@ -541,7 +543,7 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) TBM_SNRPRINTF(str, len, c, "%s\n", data); for (i = 0; i < surf->num_bos; i++) { - size = tbm_bo_data_get_size(surf->bos[i]->bo_data, &error); + size = tbm_bo_data_get_size(surf->bos[i]->bo_data, error); if (error != TBM_ERROR_NONE) TBM_WRN("fail to get the size of bo."); TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n", @@ -564,10 +566,10 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) tbm_key key = 0; LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) { - size = tbm_bo_data_get_size(bo->bo_data, &error); + size = tbm_bo_data_get_size(bo->bo_data, error); if (error != TBM_ERROR_NONE) TBM_WRN("fail to get the size of bo."); - key = tbm_bo_data_export_key(bo->bo_data, &error); + key = tbm_bo_data_export_key(bo->bo_data, error); if (error != TBM_ERROR_NONE) TBM_WRN("fail to get the tdm_key of bo."); TBM_SNRPRINTF(str, len, c, "%-3d %-11p %-5d %-7d %-6d %-5u %-7d %-11p %-4d\n", @@ -587,6 +589,27 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) TBM_SNRPRINTF(str, len, c, "========================================================================================================\n"); + return str; +} + +char * +tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) +{ + char *str; + tbm_error_e error = TBM_ERROR_NONE; + + pthread_mutex_lock(&gLock); + _tbm_set_last_result(TBM_ERROR_NONE); + + str = _tbm_bufmgr_debug_tbm_info_get(bufmgr, &error); + if (!str) { + TBM_ERR("tbm_bufmgr_internal_debug_tbm_info_get failed."); + _tbm_set_last_result(error); + pthread_mutex_unlock(&gLock); + return NULL; + } + + _tbm_set_last_result(error); pthread_mutex_unlock(&gLock); return str; -- 2.7.4