Added mutex code for command 18/227618/2
authorsungrae jo <seongrae.jo@samsung.com>
Mon, 16 Mar 2020 03:40:01 +0000 (12:40 +0900)
committersungrae jo <seongrae.jo@samsung.com>
Mon, 16 Mar 2020 03:40:01 +0000 (12:40 +0900)
Change-Id: I51b58c5310a87b5987a28a6502f0b01890e3f36d
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
common/vc_command.c

index 8ff713868e4ef1a6e42f3e657e0ef82ccefec164..e271c0b502f90ecdddfb2b04d655be8281159a70 100644 (file)
 #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;
 }