From 29cf0c534ff5a820c1acd14a646778e374404213 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Tue, 6 Feb 2024 12:17:08 +0900 Subject: [PATCH] Added mutex lock for avoiding the data race condition When it updates g_config_info, it needs mutex lock for preventing the data race condition. When it accesses g_app_list, it needs mutex lock for preventing the data race condition. Change-Id: I7b094b377a81e1e4fa35bf6cf6332a6baef8f83e --- common/tts_config_parser.c | 2 ++ server/ttsd_data.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c index 901b09a..d489336 100644 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -553,7 +553,9 @@ int tts_parser_load_config(void) cur = cur->next; } + pthread_mutex_lock(&g_config_info_mutex); g_config_info = temp; + pthread_mutex_unlock(&g_config_info_mutex); g_config_doc = doc; if (true == is_default_open) { diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index efca767..bce9b64 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -299,6 +299,7 @@ int ttsd_data_is_client(unsigned int uid) int ttsd_data_get_client_count() { + lock_guard lock(g_app_data_mutex); int num_client = g_app_list.size(); SLOG(LOG_INFO, tts_tag(), "[DATA INFO] Number of clients(%d)", num_client); -- 2.7.4