Remove shared variable for callback timer 89/246889/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 30 Oct 2020 07:32:15 +0000 (16:32 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 5 Nov 2020 03:29:32 +0000 (12:29 +0900)
To call client callback asynchronously, current code uses Ecore_timer with shared variable.
But this implementation can cause unexpected problem when multi clients exist.

This patch removes shared Ecore_timer variables and makes Ecore_timer vairable for each clients
on tts_client_s.

Change-Id: I5b298cb55bed27f52e6cab697eca67c6c5441192
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c

index ff6427cb10114c3dd35619fe8c8f9fb394c47c13..4b50e781ee6368f5ec1569714b7272cc48fd85f0 100644 (file)
@@ -38,9 +38,6 @@ static int g_feature_enabled = -1;
 
 static int g_max_text_size = -1;
 
-static Ecore_Timer* g_check_state_timer = NULL;
-static Ecore_Timer* g_notify_error_timer = NULL;
-
 /* for repetition */
 static char* g_language = NULL;
 
@@ -603,6 +600,17 @@ int tts_destroy(tts_h tts)
                        thread_count = ecore_thread_active_get();
                }
 
+               /* Delete state timer before destroying handle */
+               if (NULL != client->notify_state_timer) {
+                       ecore_timer_del(client->notify_state_timer);
+                       client->notify_state_timer = NULL;
+               }
+               /* Delete error timer before destroying handle */
+               if (NULL != client->notify_error_timer) {
+                       ecore_timer_del(client->notify_error_timer);
+                       client->notify_error_timer = NULL;
+               }
+
                /* Free resources */
                tts_client_destroy(tts);
 
@@ -638,16 +646,6 @@ int tts_destroy(tts_h tts)
                g_language = NULL;
        }
 
-       /* Delete state timer before destroying handle */
-       if (NULL != g_check_state_timer) {
-               ecore_timer_del(g_check_state_timer);
-               g_check_state_timer = NULL;
-       }
-       /* Delete error timer before destroying handle */
-       if (NULL != g_notify_error_timer) {
-               ecore_timer_del(g_notify_error_timer);
-               g_notify_error_timer = NULL;
-       }
 
        tts = NULL;
 
@@ -1433,11 +1431,10 @@ static void __tts_play_async(void *data)
                client->reason = ret;
                client->utt_id = -1;
 
-               if (NULL != g_notify_error_timer) {
-                       ecore_timer_del(g_notify_error_timer);
-                       g_notify_error_timer = NULL;
+               if (NULL != client->notify_error_timer) {
+                       ecore_timer_del(client->notify_error_timer);
                }
-               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
+               client->notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                return;
        }
 
@@ -1635,11 +1632,10 @@ static void __tts_stop_async(void *data)
                client->reason = ret;
                client->utt_id = -1;
 
-               if (NULL != g_notify_error_timer) {
-                       ecore_timer_del(g_notify_error_timer);
-                       g_notify_error_timer = NULL;
+               if (NULL != client->notify_error_timer) {
+                       ecore_timer_del(client->notify_error_timer);
                }
-               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
+               client->notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                return;
        }
 
@@ -1825,11 +1821,10 @@ static void __tts_pause_async(void *data)
                client->reason = ret;
                client->utt_id = -1;
 
-               if (NULL != g_notify_error_timer) {
-                       ecore_timer_del(g_notify_error_timer);
-                       g_notify_error_timer = NULL;
+               if (NULL != client->notify_error_timer) {
+                       ecore_timer_del(client->notify_error_timer);
                }
-               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
+               client->notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                return;
        }
 
@@ -2120,7 +2115,6 @@ static Eina_Bool __tts_notify_error(void *data)
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_WARN, TAG_TTSC, "Fail to notify error msg : A handle is not valid");
-               g_notify_error_timer = NULL;
                return EINA_FALSE;
        }
 
@@ -2128,7 +2122,7 @@ static Eina_Bool __tts_notify_error(void *data)
 
        tts_core_notify_error(client, client->utt_id, client->reason);
 
-       g_notify_error_timer = NULL;
+       client->notify_error_timer = NULL;
 
        return EINA_FALSE;
 }
@@ -2251,11 +2245,10 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 
                                /* call callback function */
                                if (NULL != data->error_cb) {
-                                       if (NULL != g_notify_error_timer) {
-                                               ecore_timer_del(g_notify_error_timer);
-                                               g_notify_error_timer = NULL;
+                                       if (NULL != data->notify_error_timer) {
+                                               ecore_timer_del(data->notify_error_timer);
                                        }
-                                       g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, data->tts);
+                                       data->notify_error_timer = ecore_timer_add(0, __tts_notify_error, data->tts);
                                } else {
                                        SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
                                }
@@ -2303,11 +2296,10 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 
                /* call callback function */
                if (NULL != client->error_cb) {
-                       if (NULL != g_notify_error_timer) {
-                               ecore_timer_del(g_notify_error_timer);
-                               g_notify_error_timer = NULL;
+                       if (NULL != client->notify_error_timer) {
+                               ecore_timer_del(client->notify_error_timer);
                        }
-                       g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
+                       client->notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                } else {
                        SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
                }
@@ -2337,14 +2329,12 @@ static Eina_Bool __tts_notify_state_changed(void *data)
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_WARN, TAG_TTSC, "Fail to notify state changed : A handle is not valid");
-               g_check_state_timer = NULL;
                return EINA_FALSE;
        }
 
        tts_core_notify_state_changed(client, client->before_state, client->current_state);
 
-       g_check_state_timer = NULL;
-
+       client->notify_state_timer = NULL;
        return EINA_FALSE;
 }
 
@@ -2364,11 +2354,10 @@ int __tts_cb_set_state(int uid, int state)
        }
 
        if (NULL != client->state_changed_cb) {
-               if (NULL != g_check_state_timer) {
-                       ecore_timer_del(g_check_state_timer);
-                       g_check_state_timer = NULL;
+               if (NULL != client->notify_state_timer) {
+                       ecore_timer_del(client->notify_state_timer);
                }
-               g_check_state_timer = ecore_timer_add(0, __tts_notify_state_changed, client->tts);
+               client->notify_state_timer = ecore_timer_add(0, __tts_notify_state_changed, client->tts);
        } else {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
        }
@@ -2473,9 +2462,9 @@ int tts_unset_state_changed_cb(tts_h tts)
        client->state_changed_cb = NULL;
        client->state_changed_user_data = NULL;
 
-       if (NULL != g_check_state_timer) {
-               ecore_timer_del(g_check_state_timer);
-               g_check_state_timer = NULL;
+       if (NULL != client->notify_state_timer) {
+               ecore_timer_del(client->notify_state_timer);
+               client->notify_state_timer = NULL;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
@@ -2663,6 +2652,11 @@ int tts_unset_error_cb(tts_h tts)
        client->error_cb = NULL;
        client->error_user_data = NULL;
 
+       if (NULL != client->notify_error_timer) {
+               ecore_timer_del(client->notify_error_timer);
+               client->notify_error_timer = NULL;
+       }
+
        SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
 
        return 0;