From 8b0e10002a43e382989739f8b9ed0992dd22bef8 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 3 Jan 2017 15:18:28 +0900 Subject: [PATCH] Change mutex API Modify g_mutex_trylock() to g_mutex_lock() Change-Id: I12eb424b718100a9d3a3db348d221028ce3e30b9 Signed-off-by: Minje Ahn (cherry picked from commit 8569eeb41e3d7e8abec8308ecd67dfa79603ccb7) --- packaging/capi-content-media-content.spec | 2 +- src/media_content.c | 118 ++++++++++++++---------------- 2 files changed, 56 insertions(+), 64 deletions(-) diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 1149da8..f3f35db 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.2.92 +Version: 0.2.93 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_content.c b/src/media_content.c index 1387e20..a699b01 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -996,43 +996,39 @@ int media_content_connect(void) { int ret = MEDIA_CONTENT_ERROR_NONE; - if (g_mutex_trylock(&db_mutex)) { - media_content_info("ref count : %d", ref_count); - - if (ref_count == 0) { - if (db_handle == NULL) { - ret = __media_content_create_attribute_handle(); - if (ret == MEDIA_CONTENT_ERROR_NONE) { - ret = media_svc_connect(&db_handle, tzplatform_getuid(TZ_USER_NAME), false); - ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); - if (ret == MEDIA_CONTENT_ERROR_NONE) - ref_count++; - else - __media_content_destroy_attribute_handle(); + g_mutex_lock(&db_mutex); + media_content_info("ref count : %d", ref_count); + + if (ref_count == 0) { + if (db_handle == NULL) { + ret = __media_content_create_attribute_handle(); + if (ret == MEDIA_CONTENT_ERROR_NONE) { + ret = media_svc_connect(&db_handle, tzplatform_getuid(TZ_USER_NAME), false); + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + if (ret == MEDIA_CONTENT_ERROR_NONE) + ref_count++; + else + __media_content_destroy_attribute_handle(); - } else { - media_content_error("Internal DB Connection Error"); - } } else { - media_content_error("Wrong DB Connection status"); - ret = MEDIA_CONTENT_ERROR_DB_FAILED; + media_content_error("Internal DB Connection Error"); } } else { - if (db_handle != NULL) { - ref_count++; - } else { - media_content_error("Wrong DB Handle status"); - ret = MEDIA_CONTENT_ERROR_DB_FAILED; - } + media_content_error("Wrong DB Connection status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; } - - media_content_info("ref count changed to: %d", ref_count); - g_mutex_unlock(&db_mutex); } else { - media_content_error("mutex is NULL"); - ret = MEDIA_CONTENT_ERROR_DB_FAILED; + if (db_handle != NULL) { + ref_count++; + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } } + media_content_info("ref count changed to: %d", ref_count); + g_mutex_unlock(&db_mutex); + return ret; } @@ -1040,50 +1036,46 @@ int media_content_disconnect(void) { int ret = MEDIA_CONTENT_ERROR_NONE; - if (g_mutex_trylock(&db_mutex)) { - media_content_debug("ref count : %d", ref_count); - if (ref_count > 0) { - if (db_handle != NULL) { - ref_count--; - } else { - media_content_error("Wrong DB Handle status"); - ret = MEDIA_CONTENT_ERROR_DB_FAILED; - } + g_mutex_lock(&db_mutex); + media_content_debug("ref count : %d", ref_count); + if (ref_count > 0) { + if (db_handle != NULL) { + ref_count--; } else { - media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED); - g_mutex_unlock(&db_mutex); - return MEDIA_CONTENT_ERROR_DB_FAILED; + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; } + } else { + media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED); + g_mutex_unlock(&db_mutex); + return MEDIA_CONTENT_ERROR_DB_FAILED; + } - if (ref_count == 0) { - if (db_handle != NULL) { - ret = media_svc_disconnect(db_handle); - ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); - if (ret == MEDIA_CONTENT_ERROR_NONE) { - ret = __media_content_destroy_attribute_handle(); - db_handle = NULL; - } else { - media_content_error("database disconnect fail"); - ref_count++; - } + if (ref_count == 0) { + if (db_handle != NULL) { + ret = media_svc_disconnect(db_handle); + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + if (ret == MEDIA_CONTENT_ERROR_NONE) { + ret = __media_content_destroy_attribute_handle(); + db_handle = NULL; } else { - media_content_error("Wrong DB Handle status"); - ret = MEDIA_CONTENT_ERROR_DB_FAILED; + media_content_error("database disconnect fail"); + ref_count++; } - - g_mutex_unlock(&db_mutex); - - media_content_info("ref count changed to: %d", ref_count); - - return ret; + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; } g_mutex_unlock(&db_mutex); - } else { - media_content_error("mutex is NULL"); - ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION; + + media_content_info("ref count changed to: %d", ref_count); + + return ret; } + g_mutex_unlock(&db_mutex); + media_content_info("ref count changed to: %d", ref_count); return ret; -- 2.7.4