From 61844e83cabd54aee557e8b411233f5a6c8ce17b Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Mon, 16 Mar 2020 12:40:01 +0900 Subject: [PATCH] Added mutex code for command Change-Id: I51b58c5310a87b5987a28a6502f0b01890e3f36d Signed-off-by: sungrae jo --- common/vc_command.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/vc_command.c b/common/vc_command.c index 8ff7138..e271c0b 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -33,6 +33,10 @@ #include "voice_control_common.h" #include "voice_control_key_defines.h" +static pthread_mutex_t g_cmd_mutex = PTHREAD_MUTEX_INITIALIZER; +#define CMD_MUTEX_LOCK() pthread_mutex_lock(&g_cmd_mutex) +#define CMD_MUTEX_UNLOCK() pthread_mutex_unlock(&g_cmd_mutex) + static int g_feature_enabled = -1; static bool g_privilege_allowed = false; @@ -658,8 +662,11 @@ int vc_cmd_create(vc_cmd_h* vc_command) return VC_ERROR_PERMISSION_DENIED; } + CMD_MUTEX_LOCK(); + if (NULL == vc_command) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL"); + CMD_MUTEX_UNLOCK(); return VC_ERROR_INVALID_PARAMETER; } @@ -667,6 +674,7 @@ int vc_cmd_create(vc_cmd_h* vc_command) if (NULL == command) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory"); + CMD_MUTEX_UNLOCK(); return VC_ERROR_OUT_OF_MEMORY; } @@ -692,6 +700,7 @@ int vc_cmd_create(vc_cmd_h* vc_command) SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command); + CMD_MUTEX_UNLOCK(); return VC_ERROR_NONE; } @@ -704,8 +713,11 @@ int vc_cmd_destroy(vc_cmd_h vc_command) return VC_ERROR_PERMISSION_DENIED; } + CMD_MUTEX_LOCK(); + if (NULL == vc_command) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL"); + CMD_MUTEX_UNLOCK(); return VC_ERROR_INVALID_PARAMETER; } @@ -718,6 +730,7 @@ int vc_cmd_destroy(vc_cmd_h vc_command) iter = g_list_find(g_cmd_list, command); if (NULL == iter) { SLOG(LOG_ERROR, TAG_VCCMD, "Fail to command destroy : handle is not valid"); + CMD_MUTEX_UNLOCK(); return VC_ERROR_INVALID_PARAMETER; } @@ -744,6 +757,7 @@ int vc_cmd_destroy(vc_cmd_h vc_command) free(command); command = NULL; + CMD_MUTEX_UNLOCK(); return VC_ERROR_NONE; } -- 2.7.4