Clear player data after play thread is stopped 18/261018/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 8 Jul 2021 09:59:46 +0000 (18:59 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 8 Jul 2021 12:24:29 +0000 (21:24 +0900)
Previous code clears player data before reset the g_playing_info. If play thread still play
some text, race condition of player data(ex. pasued_data) may occur.

This patch changes the order of function call that 'ttsd_player_clear()' is invoked after
play thread is stopped.
By this change, player data is safe to access from other thread.

Change-Id: Ia768cf76a876956a591974f9bc7871dcbdffe1c0
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_player.c

index ebbb5ef..1872414 100644 (file)
@@ -1370,12 +1370,6 @@ int ttsd_player_play(int uid)
 int ttsd_player_stop(int uid)
 {
        pthread_mutex_lock(&g_player_control_mutex);
-       int ret = ttsd_player_clear(uid);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to stop player, ret(%d)", ret);
-               pthread_mutex_unlock(&g_player_control_mutex);
-               return ret;
-       }
 
        /* check whether uid is current playing or not */
        if (NULL != g_playing_info) {
@@ -1393,6 +1387,14 @@ int ttsd_player_stop(int uid)
                SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
                SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
        }
+
+       int ret = ttsd_player_clear(uid);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to stop player, ret(%d)", ret);
+               pthread_mutex_unlock(&g_play_thread_mutex);
+               pthread_mutex_unlock(&g_player_control_mutex);
+               return ret;
+       }
        pthread_mutex_unlock(&g_play_thread_mutex);
 
        SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);