From: Wonnam Jang Date: Tue, 12 Sep 2017 01:32:13 +0000 (+0900) Subject: Add critical section to avoid thread safety issue X-Git-Tag: accepted/tizen/4.0/unified/20170922.064439^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fstt.git;a=commitdiff_plain;h=2e73c26e5b7baac7c43593e770cddc5bf9225af2 Add critical section to avoid thread safety issue Change-Id: Ie5fc64abd2285aae4d69e2594108dc4eefe30d66 Signed-off-by: Wonnam Jang (cherry picked from commit 486aa7d2f3c3634c5636110fa2f031ead312fb11) --- diff --git a/server/sttd_recorder.c b/server/sttd_recorder.c index 16202d0..b83cc47 100644 --- a/server/sttd_recorder.c +++ b/server/sttd_recorder.c @@ -593,9 +593,14 @@ int sttd_recorder_stop() if (STTD_RECORDER_STATE_READY == g_recorder_state) return 0; + // critical section required because this function can be called from stt engine thread context + SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section"); + pthread_mutex_lock(&sttd_audio_in_handle_mutex); + /* Check engine id is valid */ if (NULL == g_recorder) { SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid"); + pthread_mutex_unlock(&sttd_audio_in_handle_mutex); return STTD_ERROR_INVALID_PARAMETER; } @@ -636,6 +641,8 @@ int sttd_recorder_stop() #ifdef BUF_SAVE_MODE fclose(g_pFile); #endif + pthread_mutex_unlock(&sttd_audio_in_handle_mutex); + SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Leave critical section"); return 0; }