diff options
-rw-r--r-- | src/tbm_bufmgr.c | 284 |
1 files changed, 159 insertions, 125 deletions
diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index bd66449..52ac184 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -48,8 +48,15 @@ int bTrace; int bDlog; #endif +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 __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE; + +static void _tbm_bufmgr_mutex_unlock(void); + #define PREFIX_LIB "libtbm_" #define SUFFIX_LIB ".so" #define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB @@ -66,23 +73,67 @@ int b_dump_queue; #define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) #define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) +/* check condition */ +#define TBM_BUFMGR_RETURN_IF_FAIL(cond) {\ + if (!(cond)) {\ + TBM_LOG_E("'%s' failed.\n", #cond);\ + _tbm_bufmgr_mutex_unlock();\ + return;\ + } \ +} +#define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\ + if (!(cond)) {\ + TBM_LOG_E("'%s' failed.\n", #cond);\ + _tbm_bufmgr_mutex_unlock();\ + return val;\ + } \ +} + enum { LOCK_TRY_ONCE, LOCK_TRY_ALWAYS, LOCK_TRY_NEVER }; -pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; -tbm_bufmgr gBufMgr; - -static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE; - static void _tbm_set_last_result(tbm_error_e err) { tbm_last_error = err; } +static bool +_tbm_bufmgr_mutex_init(void) +{ + static bool tbm_bufmgr_mutex_init = false; + + if (tbm_bufmgr_mutex_init) + return true; + + if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) { + TBM_LOG_E("fail: tbm_bufmgr mutex init\n"); + return false; + } + + tbm_bufmgr_mutex_init = true; + + return true; +} + +static void +_tbm_bufmgr_mutex_lock(void) +{ + if (!_tbm_bufmgr_mutex_init()) + return; + + pthread_mutex_lock(&_tbm_bufmgr_lock); +} + +static void +_tbm_bufmgr_mutex_unlock(void) +{ + pthread_mutex_unlock(&_tbm_bufmgr_lock); +} + char * tbm_flag_to_str(int f) { static char str[255]; @@ -285,17 +336,17 @@ _tbm_bo_lock(tbm_bo bo, int device, int opt) old = bo->lock_cnt; if (bufmgr->lock_type == LOCK_TRY_ONCE) { if (bo->lock_cnt == 0) { - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); ret = _bo_lock(bo, device, opt); - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (ret) bo->lock_cnt++; } else ret = 1; } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) { - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); ret = _bo_lock(bo, device, opt); - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (ret) bo->lock_cnt++; } else { @@ -632,19 +683,6 @@ tbm_bufmgr_init(int fd) DBG("create tizen bufmgr:%p ref_count:%d\n", gBufMgr, gBufMgr->ref_count); - if (pthread_mutex_init(&gBufMgr->lock, NULL) != 0) { - /* LCOV_EXCL_START */ - _tbm_set_last_result(TBM_BO_ERROR_THREAD_INIT_FAILED); - gBufMgr->backend->bufmgr_deinit(gBufMgr->backend->priv); - tbm_backend_free(gBufMgr->backend); - dlclose(gBufMgr->module_data); - free(gBufMgr); - gBufMgr = NULL; - pthread_mutex_unlock(&gLock); - return NULL; - /* LCOV_EXCL_STOP */ - } - /* setup the lock_type */ env = getenv("BUFMGR_LOCK_TYPE"); if (env && !strcmp(env, "always")) @@ -671,6 +709,7 @@ tbm_bufmgr_init(int fd) LIST_INITHEAD(&gBufMgr->debug_key_list); pthread_mutex_unlock(&gLock); + return gBufMgr; } @@ -725,8 +764,6 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) tbm_backend_free(bufmgr->backend); bufmgr->backend = NULL; - pthread_mutex_destroy(&bufmgr->lock); - TBM_TRACE("destroy tbm_bufmgr(%p)\n", bufmgr); dlclose(bufmgr->module_data); @@ -744,24 +781,21 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr) int tbm_bo_size(tbm_bo bo) { - TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - - tbm_bufmgr bufmgr = gBufMgr; + tbm_bufmgr bufmgr = NULL; int size; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); - if (!_tbm_bo_is_valid(bo)) { - TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); - return 0; - } + TBM_BUFMGR_VAL_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); + TBM_BUFMGR_VAL_RETURN_IF_FAIL(_tbm_bo_is_valid(bo), 0); + + bufmgr = gBufMgr; size = bufmgr->backend->bo_size(bo); TBM_TRACE("bo(%p) size(%d)\n", bo, size); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return size; } @@ -769,23 +803,21 @@ tbm_bo_size(tbm_bo bo) tbm_bo tbm_bo_ref(tbm_bo bo) { - TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL); + tbm_bufmgr bufmgr = NULL; + int size; - tbm_bufmgr bufmgr = gBufMgr; + _tbm_bufmgr_mutex_lock(); - pthread_mutex_lock(&bufmgr->lock); + TBM_BUFMGR_VAL_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL); + TBM_BUFMGR_VAL_RETURN_IF_FAIL(_tbm_bo_is_valid(bo), NULL); - if (!_tbm_bo_is_valid(bo)) { - TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); - return NULL; - } + bufmgr = gBufMgr; _tbm_bo_ref(bo); TBM_TRACE("bo(%p) ref_cnt(%d)\n", bo, bo->ref_cnt); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo; } @@ -793,15 +825,17 @@ tbm_bo_ref(tbm_bo bo) void tbm_bo_unref(tbm_bo bo) { - TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr)); - tbm_bufmgr bufmgr = gBufMgr; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); + + TBM_BUFMGR_RETURN_IF_FAIL(gBufMgr); + TBM_BUFMGR_RETURN_IF_FAIL(_tbm_bo_is_valid(bo); + if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return; } @@ -809,7 +843,7 @@ tbm_bo_unref(tbm_bo bo) _tbm_bo_unref(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); } tbm_bo @@ -829,7 +863,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) return NULL; } - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); _tbm_util_check_bo_cnt(bufmgr); bufmgr->bo_cnt++; @@ -841,7 +875,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) TBM_TRACE("error: fail to create of tbm_bo size(%d) flag(%s)\n", size, tbm_flag_to_str(flags)); _tbm_set_last_result(TBM_BO_ERROR_BO_ALLOC_FAILED); free(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -855,7 +889,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags) LIST_ADD(&bo->item_link, &bufmgr->bo_list); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo; } @@ -871,10 +905,10 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) tbm_bo tmp = NULL; void *bo_priv = NULL; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!bufmgr->backend->bo_import) { - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -883,7 +917,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) bo = calloc(1, sizeof(struct _tbm_bo)); if (!bo) { TBM_TRACE("error: fail to import of tbm_bo by key(%d)\n", key); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -896,7 +930,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) TBM_TRACE("error: fail to import of tbm_bo by key(%d)\n", key); _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FAILED); free(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -907,7 +941,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) bo2, bo2->ref_cnt, key, tbm_flag_to_str(bo2->flags)); bo2->ref_cnt++; free(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo2; } } @@ -928,7 +962,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key) LIST_ADD(&bo->item_link, &bufmgr->bo_list); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo; } @@ -944,10 +978,10 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) tbm_bo tmp = NULL; void *bo_priv = NULL; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!bufmgr->backend->bo_import_fd) { - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -956,7 +990,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) bo = calloc(1, sizeof(struct _tbm_bo)); if (!bo) { TBM_TRACE("error: fail to import tbm_bo by tbm_fd(%d)\n", fd); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -969,7 +1003,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) TBM_TRACE("error: fail to import tbm_bo by tbm_fd(%d)\n", fd); _tbm_set_last_result(TBM_BO_ERROR_IMPORT_FD_FAILED); free(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return NULL; } @@ -980,7 +1014,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) bo2, bo2->ref_cnt, fd, tbm_flag_to_str(bo2->flags)); bo2->ref_cnt++; free(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo2; } } @@ -1001,7 +1035,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd) LIST_ADD(&bo->item_link, &bufmgr->bo_list); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo; } @@ -1014,16 +1048,16 @@ tbm_bo_export(tbm_bo bo) tbm_bufmgr bufmgr = gBufMgr; tbm_key ret; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!bufmgr->backend->bo_export) { - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1031,13 +1065,13 @@ tbm_bo_export(tbm_bo bo) if (!ret) { _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FAILED); TBM_TRACE("error: bo(%p) tbm_key(%d)\n", bo, ret); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return ret; } TBM_TRACE("bo(%p) tbm_key(%d)\n", bo, ret); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return ret; } @@ -1050,16 +1084,16 @@ tbm_bo_export_fd(tbm_bo bo) tbm_bufmgr bufmgr = gBufMgr; int ret; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!bufmgr->backend->bo_export_fd) { - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1067,13 +1101,13 @@ tbm_bo_export_fd(tbm_bo bo) if (ret < 0) { _tbm_set_last_result(TBM_BO_ERROR_EXPORT_FD_FAILED); TBM_TRACE("error: bo(%p) tbm_fd(%d)\n", bo, ret); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return ret; } TBM_TRACE("bo(%p) tbm_fd(%d)\n", bo, ret); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return ret; } @@ -1086,11 +1120,11 @@ tbm_bo_get_handle(tbm_bo bo, int device) tbm_bufmgr bufmgr = gBufMgr; tbm_bo_handle bo_handle; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return (tbm_bo_handle) NULL; } @@ -1098,13 +1132,13 @@ tbm_bo_get_handle(tbm_bo bo, int device) if (bo_handle.ptr == NULL) { _tbm_set_last_result(TBM_BO_ERROR_GET_HANDLE_FAILED); TBM_TRACE("error: bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return (tbm_bo_handle) NULL; } TBM_TRACE("bo(%p) bo_handle(%p)\n", bo, bo_handle.ptr); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo_handle; } @@ -1117,18 +1151,18 @@ tbm_bo_map(tbm_bo bo, int device, int opt) tbm_bufmgr bufmgr = gBufMgr; tbm_bo_handle bo_handle; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return (tbm_bo_handle) NULL; } if (!_tbm_bo_lock(bo, device, opt)) { _tbm_set_last_result(TBM_BO_ERROR_LOCK_FAILED); TBM_TRACE("error: fail to lock bo:%p)\n", bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return (tbm_bo_handle) NULL; } @@ -1137,7 +1171,7 @@ tbm_bo_map(tbm_bo bo, int device, int opt) _tbm_set_last_result(TBM_BO_ERROR_MAP_FAILED); TBM_TRACE("error: fail to map bo:%p\n", bo); _tbm_bo_unlock(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return (tbm_bo_handle) NULL; } @@ -1146,7 +1180,7 @@ tbm_bo_map(tbm_bo bo, int device, int opt) TBM_TRACE("bo(%p) map_cnt(%d)\n", bo, bo->map_cnt); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return bo_handle; } @@ -1159,11 +1193,11 @@ tbm_bo_unmap(tbm_bo bo) tbm_bufmgr bufmgr = gBufMgr; int ret; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1171,7 +1205,7 @@ tbm_bo_unmap(tbm_bo bo) if (!ret) { TBM_TRACE("error: bo(%p) map_cnt(%d)\n", bo, bo->map_cnt); _tbm_set_last_result(TBM_BO_ERROR_UNMAP_FAILED); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return ret; } @@ -1182,7 +1216,7 @@ tbm_bo_unmap(tbm_bo bo) _tbm_bo_unlock(bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return ret; } @@ -1195,17 +1229,17 @@ tbm_bo_swap(tbm_bo bo1, tbm_bo bo2) tbm_bufmgr bufmgr = gBufMgr; void *temp; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo1)) { TBM_LOG_E("_tbm_bo_is_valid(bo1) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (!_tbm_bo_is_valid(bo2)) { TBM_LOG_E("_tbm_bo_is_valid(bo2) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1214,7 +1248,7 @@ tbm_bo_swap(tbm_bo bo1, tbm_bo bo2) if (bufmgr->backend->bo_size(bo1) != bufmgr->backend->bo_size(bo2)) { _tbm_set_last_result(TBM_BO_ERROR_SWAP_FAILED); TBM_TRACE("error: bo1(%p) bo2(%p)\n", bo1, bo2); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1236,28 +1270,28 @@ tbm_bo_locked(tbm_bo bo) tbm_bufmgr bufmgr = gBufMgr; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (bufmgr->lock_type == LOCK_TRY_NEVER) { TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (bo->lock_cnt > 0) { TBM_TRACE("error: bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } TBM_TRACE("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1271,11 +1305,11 @@ tbm_bo_add_user_data(tbm_bo bo, unsigned long key, tbm_bufmgr bufmgr = gBufMgr; tbm_user_data *data; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1283,14 +1317,14 @@ tbm_bo_add_user_data(tbm_bo bo, unsigned long key, data = user_data_lookup(&bo->user_data_list, key); if (data) { TBM_TRACE("warning: user data already exist key(%ld)\n", key); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } data = user_data_create(key, data_free_func); if (!data) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1298,7 +1332,7 @@ tbm_bo_add_user_data(tbm_bo bo, unsigned long key, LIST_ADD(&data->item_link, &bo->user_data_list); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } @@ -1311,24 +1345,24 @@ tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data) tbm_bufmgr bufmgr = gBufMgr; tbm_user_data *old_data; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (LIST_IS_EMPTY(&bo->user_data_list)) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } old_data = user_data_lookup(&bo->user_data_list, key); if (!old_data) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1339,7 +1373,7 @@ tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data) TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } @@ -1352,17 +1386,17 @@ tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data) tbm_bufmgr bufmgr = gBufMgr; tbm_user_data *old_data; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (!data || LIST_IS_EMPTY(&bo->user_data_list)) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1370,7 +1404,7 @@ tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data) if (!old_data) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); *data = NULL; - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1378,7 +1412,7 @@ tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data) TBM_TRACE("bo(%p) key(%lu) data(%p)\n", bo, key, old_data->data); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } @@ -1391,24 +1425,24 @@ tbm_bo_delete_user_data(tbm_bo bo, unsigned long key) tbm_bufmgr bufmgr = gBufMgr; tbm_user_data *old_data = (void *)0; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } if (LIST_IS_EMPTY(&bo->user_data_list)) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); return 0; } old_data = user_data_lookup(&bo->user_data_list, key); if (!old_data) { TBM_TRACE("error: bo(%p) key(%lu)\n", bo, key); - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); return 0; } @@ -1416,7 +1450,7 @@ tbm_bo_delete_user_data(tbm_bo bo, unsigned long key) user_data_delete(old_data); - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); return 1; } @@ -1439,11 +1473,11 @@ tbm_bo_get_flags(tbm_bo bo) tbm_bufmgr bufmgr = gBufMgr; int flags; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } @@ -1451,7 +1485,7 @@ tbm_bo_get_flags(tbm_bo bo) TBM_TRACE("bo(%p)\n", bo); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return flags; } @@ -1657,17 +1691,17 @@ _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface) { TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0); - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!_tbm_bo_is_valid(bo)) { TBM_LOG_E("_tbm_bo_is_valid(bo) failed.\n"); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } bo->surface = surface; - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } @@ -1680,24 +1714,24 @@ tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay) int ret; - pthread_mutex_lock(&bufmgr->lock); + _tbm_bufmgr_mutex_lock(); if (!bufmgr->backend->bufmgr_bind_native_display) { TBM_TRACE("error: tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, NativeDisplay); if (!ret) { TBM_TRACE("error: tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 0; } TBM_TRACE("tbm_bufmgr(%p) NativeDisplay(%p)\n", bufmgr, NativeDisplay); - pthread_mutex_unlock(&bufmgr->lock); + _tbm_bufmgr_mutex_unlock(); return 1; } |