Avoid infinite blocking on internalWait() by replacing cond_wait with cond_timedwait 12/221312/3 accepted/tizen/unified/20200101.120535 submit/tizen/20191231.054651
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 31 Dec 2019 05:03:18 +0000 (14:03 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 31 Dec 2019 05:27:42 +0000 (05:27 +0000)
[Version] 0.5.22
[Issue Type] Deadlock

Change-Id: If7064ca734a93a8c75b88b18298f5868feffdfad

packaging/capi-media-audio-io.spec
src/cpp/CAudioIO.cpp

index 8933b38..62a471c 100644 (file)
@@ -1,6 +1,6 @@
 Name:           capi-media-audio-io
 Summary:        An Audio Input & Audio Output library in Tizen Native API
-Version:        0.5.21
+Version:        0.5.22
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
index b1a278c..bda8400 100644 (file)
@@ -19,6 +19,8 @@
 #include <assert.h>
 #include "CAudioIODef.h"
 #include <sound_manager_internal.h>
+#include <sys/time.h>
+#include <string.h>
 
 using namespace std;
 using namespace tizen_media_audio;
@@ -98,9 +100,27 @@ void CAudioIO::internalWait() {
 #ifdef _AUDIO_IO_DEBUG_TIMING_
     AUDIO_IO_LOGD(COLOR_RED "WAIT" COLOR_END);
 #endif
-
     pthread_mutex_lock(&__mCondMutex);
-    pthread_cond_wait(&__mCond, &__mCondMutex);
+
+    struct timeval now = { 0, };
+    struct timeval to_wait = { 0, };
+    struct timeval until = { 0, };
+    struct timespec until_ts = { 0, };
+
+    constexpr int COND_TIMEOUT_MS = 200;
+
+    gettimeofday(&now, nullptr);
+    to_wait.tv_sec = COND_TIMEOUT_MS / 1000UL;
+    to_wait.tv_usec = (COND_TIMEOUT_MS % 1000UL) * 1000UL;
+    timeradd(&now, &to_wait, &until);
+    until_ts.tv_sec = until.tv_sec;
+    until_ts.tv_nsec = until.tv_usec * 1000UL;
+
+    if (pthread_cond_timedwait(&__mCond, &__mCondMutex, &until_ts) != 0) {
+        char str_error[256];
+        AUDIO_IO_LOGE("pthread_cond_timedwait error=%s", strerror_r(errno, str_error, sizeof(str_error)));
+    }
+
     pthread_mutex_unlock(&__mCondMutex);
 }