Fix thread unsafety issue in ttsd_player_pause
[platform/core/uifw/tts.git] / server / ttsd_player.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;
+
+
 /*
 * Internal Interfaces
 */
@@ -610,12 +612,14 @@ static void __play_thread(void *data, Ecore_Thread *thread)
 
                        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;
+
                                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 */
+                       SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] release current playing info (%d)", uid);
                        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;
 
-       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);