Fix thread unsafety issue in ttsd_player_pause 28/200128/2
authorsooyeon.kim <sooyeon.kim@samsung.com>
Tue, 19 Feb 2019 10:15:26 +0000 (19:15 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Tue, 19 Feb 2019 12:59:05 +0000 (21:59 +0900)
Change-Id: I74d5c8fda0f24b158d172cf21957d492890bb8c2
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
server/ttsd_player.c
server/ttsd_server.c

index 05619db..b111ef4 100644 (file)
@@ -70,6 +70,8 @@ static audio_out_h g_audio_h;
 static sound_stream_info_h g_stream_info_h;
 
 static int g_focus_watch_id;
 static sound_stream_info_h g_stream_info_h;
 
 static int g_focus_watch_id;
+
+
 /*
 * Internal Interfaces
 */
 /*
 * Internal Interfaces
 */
@@ -610,12 +612,14 @@ static void __play_thread(void *data, Ecore_Thread *thread)
 
                        if (APP_STATE_PAUSED == player->state) {
                                /* Save data */
 
                        if (APP_STATE_PAUSED == player->state) {
                                /* Save data */
+                               SLOG(LOG_DEBUG, tts_tag(), "[Player] player(%p)", player);
                                player->paused_data = sound_data;
 
                                player->is_paused_data = true;
                                player->idx = idx;
 
                                g_audio_state = AUDIO_STATE_READY;
                                player->paused_data = sound_data;
 
                                player->is_paused_data = true;
                                player->idx = idx;
 
                                g_audio_state = AUDIO_STATE_READY;
+
                                SLOG(LOG_INFO, tts_tag(), "[Player] Stop player thread by pause");
 
                                /* Request prepare */
                                SLOG(LOG_INFO, tts_tag(), "[Player] Stop player thread by pause");
 
                                /* Request prepare */
@@ -1067,36 +1071,44 @@ int ttsd_player_pause(int uid)
        if (NULL != g_playing_info) {
                if (uid == g_playing_info->uid) {
                        /* release current playing info */
        if (NULL != g_playing_info) {
                if (uid == g_playing_info->uid) {
                        /* release current playing info */
+                       SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] release current playing info (%d)", uid);
                        g_playing_info = NULL;
                } else {
                        /* error case */
                }
        }
 
                        g_playing_info = NULL;
                } else {
                        /* error case */
                }
        }
 
+       SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] current player (%p), g_playing_info(%p)", current, g_playing_info);
+
        current->state = APP_STATE_PAUSED;
 
        current->state = APP_STATE_PAUSED;
 
-       SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
-       SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
-       SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+       if (NULL == g_playing_info) {
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+               SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
 
 
-       /* The thread should be released */
-       int thread_count = ecore_thread_active_get();
-       int count = 0;
-       while (0 < thread_count) {
-               usleep(10000);
+               /* The thread should be released */
+               int thread_count = ecore_thread_active_get();
+               int count = 0;
+               while (0 < thread_count) {
+                       usleep(10000);
 
 
-               count++;
-               if (30 == count) {
-                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
-                       break;
+                       count++;
+                       SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] current(%p), state(%d)", current, current->state);
+
+                       if (30 == count) {
+                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue. current(%p) current state(%d)", current, current->state);
+                               break;
+                       }
+
+                       thread_count = ecore_thread_active_get();
                }
 
                }
 
-               thread_count = ecore_thread_active_get();
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+               SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
        }
 
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
-       SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
-       SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
 
        SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
 
 
        SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
 
index 7f2fe64..c1b5ab8 100644 (file)
@@ -43,6 +43,9 @@ static utterance_t g_utt;
 
 static GList *g_proc_list = NULL;
 
 
 static GList *g_proc_list = NULL;
 
+static bool g_is_paused;
+
+
 /* Function definitions */
 static int __synthesis(int uid, const char* credential);
 
 /* Function definitions */
 static int __synthesis(int uid, const char* credential);
 
@@ -248,6 +251,12 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                        ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                }
 
                        ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                }
 
+               /* If the app state is paused, do not result to play */
+               if (true == g_is_paused) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[Server DEBUG] tts_pause is called. Do not request to play");
+                       return TTSD_ERROR_NONE;
+               }
+
                if (0 != ttsd_player_play(uid)) {
                        SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
 
                if (0 != ttsd_player_play(uid)) {
                        SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
 
@@ -896,6 +905,8 @@ int ttsd_server_play(int uid, const char* credential)
        if (APP_STATE_PAUSED == state) {
                SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
 
        if (APP_STATE_PAUSED == state) {
                SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
 
+               g_is_paused = false;
+
                /* Resume player */
                if (0 != ttsd_player_resume(uid)) {
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
                /* Resume player */
                if (0 != ttsd_player_resume(uid)) {
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
@@ -942,6 +953,7 @@ int ttsd_server_stop(int uid)
 
        /* Reset all data */
        ttsd_data_clear_data(uid);
 
        /* Reset all data */
        ttsd_data_clear_data(uid);
+       g_is_paused = false;
 
        return TTSD_ERROR_NONE;
 }
 
        return TTSD_ERROR_NONE;
 }
@@ -959,6 +971,8 @@ int ttsd_server_pause(int uid, int* utt_id)
                return TTSD_ERROR_INVALID_STATE;
        }
 
                return TTSD_ERROR_INVALID_STATE;
        }
 
+       g_is_paused = true;
+
        *utt_id = g_utt.uttid;
        SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
 
        *utt_id = g_utt.uttid;
        SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);