diff options
author | sungrae jo <seongrae.jo@samsung.com> | 2019-08-23 15:11:22 +0900 |
---|---|---|
committer | sungrae jo <seongrae.jo@samsung.com> | 2019-09-16 01:45:59 +0000 |
commit | 5c37dc4adced0831a686d89ecaaa69f7e7bb9c31 (patch) | |
tree | 5894c69e27ccd91927c6826efb2b00252a35c69e | |
parent | 197c2fc18553e50e8bd069fd902c4d54493a12d7 (diff) | |
download | voice-control-accepted/tizen_5.0_unified.tar.gz voice-control-accepted/tizen_5.0_unified.tar.bz2 voice-control-accepted/tizen_5.0_unified.zip |
Added mutex for widget listsubmit/tizen_5.0/20190916.055721accepted/tizen/5.0/unified/20190916.115033accepted/tizen_5.0_unified
Change-Id: I14fdcdf7e68383c8a6f3bfa5ee1b46b21482f8cd
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
(cherry picked from commit bfd06ef00407ac3bb44833d14485d2eb79555ead)
-rw-r--r-- | client/vc_widget_client.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/client/vc_widget_client.c b/client/vc_widget_client.c index e2415a6..27ee57d 100644 --- a/client/vc_widget_client.c +++ b/client/vc_widget_client.c @@ -27,6 +27,8 @@ static int g_allocated_handle = 0; /* widget list */ static GSList *g_widget_list = NULL; +static pthread_mutex_t g_widget_list_mutex = PTHREAD_MUTEX_INITIALIZER; + vc_widget_s* widget_get(vc_h vc) { if (vc == NULL) { @@ -34,6 +36,8 @@ vc_widget_s* widget_get(vc_h vc) return NULL; } + pthread_mutex_lock(&g_widget_list_mutex); + vc_widget_s *data = NULL; int count = g_slist_length(g_widget_list); @@ -44,6 +48,7 @@ vc_widget_s* widget_get(vc_h vc) if (NULL != data) { if (vc->handle == data->vc->handle) { + pthread_mutex_unlock(&g_widget_list_mutex); return data; } } @@ -51,6 +56,7 @@ vc_widget_s* widget_get(vc_h vc) SLOG(LOG_DEBUG, TAG_VCW, "[DEBUG] Fail to get widget by vc"); + pthread_mutex_unlock(&g_widget_list_mutex); return NULL; } @@ -112,7 +118,9 @@ int vc_widget_client_create(vc_h* vc) widget->cb_ref_count = 0; + pthread_mutex_lock(&g_widget_list_mutex); g_widget_list = g_slist_append(g_widget_list, widget); + pthread_mutex_unlock(&g_widget_list_mutex); *vc = temp; @@ -128,6 +136,7 @@ int vc_widget_client_destroy(vc_h vc) vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -147,6 +156,7 @@ int vc_widget_client_destroy(vc_h vc) data = NULL; vc = NULL; + pthread_mutex_unlock(&g_widget_list_mutex); return 0; } } @@ -154,12 +164,16 @@ int vc_widget_client_destroy(vc_h vc) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] widget Not found"); + pthread_mutex_unlock(&g_widget_list_mutex); return -1; } GSList* vc_widget_client_get_client_list() { - return g_widget_list; + pthread_mutex_lock(&g_widget_list_mutex); + GSList *ret = g_widget_list; + pthread_mutex_unlock(&g_widget_list_mutex); + return ret; } bool vc_widget_client_is_valid(vc_h vc) @@ -179,6 +193,7 @@ bool vc_widget_client_is_valid_by_uid(int uid) { vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -186,13 +201,16 @@ bool vc_widget_client_is_valid_by_uid(int uid) data = g_slist_nth_data(g_widget_list, i); if (NULL != data) { - if (uid == data->vc->handle) + if (uid == data->vc->handle) { + pthread_mutex_unlock(&g_widget_list_mutex); return true; + } } } SLOG(LOG_DEBUG, TAG_VCW, "[DEBUG] Fail to get widget by vc"); + pthread_mutex_unlock(&g_widget_list_mutex); return false; } @@ -200,6 +218,7 @@ int vc_widget_client_get_handle(int uid, vc_h* vc) { vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -209,11 +228,13 @@ int vc_widget_client_get_handle(int uid, vc_h* vc) if (NULL != data) { if (uid == data->vc->handle) { *vc = data->vc; + pthread_mutex_unlock(&g_widget_list_mutex); return 0; } } } + pthread_mutex_unlock(&g_widget_list_mutex); return -1; } @@ -528,6 +549,7 @@ int vc_widget_client_get_state_by_uid(int uid, vc_state_e* state) { vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -537,11 +559,13 @@ int vc_widget_client_get_state_by_uid(int uid, vc_state_e* state) if (NULL != data) { if (uid == data->vc->handle) { *state = data->current_state; + pthread_mutex_unlock(&g_widget_list_mutex); return 0; } } } + pthread_mutex_unlock(&g_widget_list_mutex); return -1; } @@ -639,7 +663,10 @@ int vc_widget_client_get_show_tooltip(vc_h vc, bool* show) int vc_widget_client_get_count() { - return g_slist_length(g_widget_list); + pthread_mutex_lock(&g_widget_list_mutex); + int ret = g_slist_length(g_widget_list); + pthread_mutex_unlock(&g_widget_list_mutex); + return ret; } int vc_widget_client_use_callback(vc_h vc) |