From ec9c73a349d6f1cc1eafa0e8da0ba2674633bbd4 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Tue, 18 Feb 2025 19:51:49 +0900 Subject: [PATCH] tbm_bufmgr: Remove unnecessary mutex lock Change-Id: Ic3c44d3ce922ed04c28edc1515b57d207480e2af --- src/tbm_bufmgr.c | 51 +++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 4acef48..4bf44e9 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -43,7 +43,6 @@ int trace_mask = 0; tbm_bufmgr gBufMgr; int b_dump_queue; -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); @@ -234,8 +233,7 @@ _tbm_bufmgr_init(int fd, int server) trace_mask = 0; #endif - pthread_mutex_lock(&gLock); - + _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); if (fd >= 0) { @@ -248,7 +246,7 @@ _tbm_bufmgr_init(int fd, int server) if (gBufMgr) { gBufMgr->ref_count++; TBM_DBG("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)", gBufMgr, gBufMgr->ref_count, gBufMgr->fd); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return gBufMgr; } @@ -259,7 +257,7 @@ _tbm_bufmgr_init(int fd, int server) if (!gBufMgr) { TBM_ERR("error: fail to alloc bufmgr fd(%d)", fd); _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -278,7 +276,7 @@ _tbm_bufmgr_init(int fd, int server) _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); free(gBufMgr); gBufMgr = NULL; - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -292,7 +290,7 @@ _tbm_bufmgr_init(int fd, int server) _tbm_set_last_result(error); free(gBufMgr); gBufMgr = NULL; - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -303,7 +301,7 @@ _tbm_bufmgr_init(int fd, int server) _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION); free(gBufMgr); gBufMgr = NULL; - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -332,7 +330,7 @@ _tbm_bufmgr_init(int fd, int server) TBM_INFO("tbm_bufmgr_init time: %ld ms", ((end_tv.tv_sec * 1000 + end_tv.tv_usec / 1000) - (start_tv.tv_sec * 1000 + start_tv.tv_usec / 1000))); #endif - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return gBufMgr; } @@ -350,21 +348,18 @@ tbm_bufmgr_init(int fd) void tbm_bufmgr_deinit(tbm_bufmgr bufmgr) { - pthread_mutex_lock(&gLock); _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); if (!TBM_BUFMGR_IS_VALID(bufmgr)) { TBM_ERR("TBM_BUFMGR_IS_VALID failed."); _tbm_bufmgr_mutex_unlock(); - pthread_mutex_unlock(&gLock); return; } if (!gBufMgr) { TBM_ERR("gBufmgr already destroy: bufmgr:%p", bufmgr); _tbm_bufmgr_mutex_unlock(); - pthread_mutex_unlock(&gLock); return; } @@ -372,7 +367,6 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) if (bufmgr->ref_count > 0) { TBM_DBG("reduce a ref_count(%d) of tbm_bufmgr(%p)", bufmgr->ref_count, bufmgr); _tbm_bufmgr_mutex_unlock(); - pthread_mutex_unlock(&gLock); return; } @@ -409,7 +403,6 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) gBufMgr = NULL; _tbm_bufmgr_mutex_unlock(); - pthread_mutex_unlock(&gLock); } unsigned int @@ -585,19 +578,19 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) char *str; tbm_error_e error = TBM_ERROR_NONE; - pthread_mutex_lock(&gLock); + _tbm_bufmgr_mutex_lock(); _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); + _tbm_bufmgr_mutex_unlock(); return NULL; } _tbm_set_last_result(error); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return str; } @@ -673,10 +666,10 @@ tbm_bufmgr_debug_set_trace_mask(tbm_bufmgr bufmgr, tbm_bufmgr_debug_trace_mask m void tbm_bufmgr_debug_dump_set_scale(double scale) { - pthread_mutex_lock(&gLock); + _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); scale_factor = scale; - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); } int @@ -684,13 +677,13 @@ tbm_bufmgr_debug_get_ref_count(void) { int refcnt; - pthread_mutex_lock(&gLock); + _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); refcnt = (gBufMgr) ? gBufMgr->ref_count : 0; - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return refcnt; } @@ -698,7 +691,7 @@ tbm_bufmgr_debug_get_ref_count(void) int tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff) { - pthread_mutex_lock(&gLock); + _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); if (onoff == 0) { @@ -710,14 +703,14 @@ tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff) if (path == NULL) { TBM_ERR("path is null"); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return 0; } TBM_DBG("path=%s count=%d onoff=%d\n", path, count, onoff); if (_tbm_util_get_max_surface_size(&w, &h) == 0) { TBM_ERR("Fail to get tbm_surface size.\n"); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -727,7 +720,7 @@ tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff) b_dump_queue = 1; } - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return 1; } @@ -738,12 +731,12 @@ tbm_bufmgr_debug_dump_all(char *path) int w, h, count = 0; tbm_surface_h surface = NULL; - pthread_mutex_lock(&gLock); + _tbm_bufmgr_mutex_lock(); _tbm_set_last_result(TBM_ERROR_NONE); if (!path) { TBM_ERR("path is null.\n"); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -752,7 +745,7 @@ tbm_bufmgr_debug_dump_all(char *path) count = _tbm_util_get_max_surface_size(&w, &h); if (count == 0) { TBM_ERR("No tbm_surface.\n"); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -764,7 +757,7 @@ tbm_bufmgr_debug_dump_all(char *path) tbm_surface_internal_dump_end(); - pthread_mutex_unlock(&gLock); + _tbm_bufmgr_mutex_unlock(); return 1; } -- 2.34.1