Fix critical section for checking thread status 78/261078/2 accepted/tizen/unified/20210716.131354 submit/tizen/20210709.113558 submit/tizen/20210714.093154
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 9 Jul 2021 08:52:36 +0000 (17:52 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 9 Jul 2021 11:12:55 +0000 (20:12 +0900)
If there are multi client handles exist, uid that wants to stop or pause can be different from uid
that is played on sub thread.
However, previous code always checks thread status although uid is not the same as played uid.
If it is different, 'ttsd_player_stop()' does not stop the thread because the uid is not
playing.
By this thread status check, deadlock can occur.

This patch makes critical section for checking thread status only when 'g_playing_info' is set as
NULL. 'g_playing_info' becomes NULL means that play thread should stop.

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

index 1872414..fbb8bd6 100644 (file)
@@ -702,7 +702,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* wait for new audio data come */
                                while (1) { // 2nd while(1)
                                        usleep(10000);
-                                       if (NULL == g_playing_info) {
+                                       if (false == __is_player_valid(player)) {
                                                /* current playing uid is replaced */
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread");
                                                if (AUDIO_STATE_PLAY == g_audio_state) {
@@ -1381,21 +1381,18 @@ int ttsd_player_stop(int uid)
                SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
        }
 
-       pthread_mutex_lock(&g_play_thread_mutex);
        if (NULL == g_playing_info) {
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+               pthread_mutex_lock(&g_play_thread_mutex);
                SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+               pthread_mutex_unlock(&g_play_thread_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_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);
 
@@ -1468,14 +1465,11 @@ int ttsd_player_pause(int uid)
 
        current->state = APP_STATE_PAUSED;
 
-       pthread_mutex_lock(&g_play_thread_mutex);
        if (NULL == g_playing_info) {
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+               pthread_mutex_lock(&g_play_thread_mutex);
                SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
+               pthread_mutex_unlock(&g_play_thread_mutex);
        }
-       pthread_mutex_unlock(&g_play_thread_mutex);
-
 
        SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);