thread-posix: retry thread joining if failed 32/239732/4 accepted/tizen/unified/20200731.145707 submit/tizen/20200730.100637 submit/tizen/20200731.014101 submit/tizen/20200731.074405
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 29 Jul 2020 08:57:19 +0000 (17:57 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 30 Jul 2020 01:45:14 +0000 (10:45 +0900)
print some logs related to threaded-mainloop

[Version] 13.0-10
[Issue Type] Debugging

Change-Id: Iaf415b422b8857ad5b84ee398da6d1535e468232

packaging/pulseaudio.spec
src/pulse/thread-mainloop.c
src/pulsecore/thread-posix.c

index 1580cd4..ec79796 100644 (file)
@@ -3,7 +3,7 @@
 Name:             pulseaudio
 Summary:          Improved Linux sound server
 Version:          13.0
-Release:          9
+Release:          10
 Group:            Multimedia/Audio
 License:          LGPL-2.1
 URL:              http://pulseaudio.org
index 18c72a9..7b4bede 100644 (file)
@@ -103,7 +103,7 @@ static void thread(void *userdata) {
     pa_mutex_unlock(m->mutex);
 
 #ifdef __TIZEN__
-    pa_log_info("thread exit : m=%p, thread=%p, name=%s", m, m->thread, m->name);
+    pa_log_info("threaded-mainloop(%p) thread(%p, %s) exit", m, m->thread, pa_thread_get_name(m->thread));
 #endif
 }
 
@@ -157,6 +157,11 @@ int pa_threaded_mainloop_start(pa_threaded_mainloop *m) {
     if (!(m->thread = pa_thread_new(m->name ? m->name : "threaded-ml", thread, m)))
         return -1;
 
+#ifdef __TIZEN__
+    pa_log_info("threaded-mainloop(%p) thread(%p, %s, running:%d) started",
+            m, m->thread, pa_thread_get_name(m->thread), pa_thread_is_running(m->thread));
+#endif
+
     return 0;
 }
 
@@ -179,7 +184,8 @@ void pa_threaded_mainloop_stop(pa_threaded_mainloop *m) {
 #ifdef __TIZEN__
     ret = pa_thread_join(m->thread);
     if (ret != 0)
-        pa_log_error("pa_thread_join failed : m=%p, thread=%p, errno=%d", m, m->thread, ret);
+        pa_log_error("threaded-mainloop(%p) thread(%p, %s, running:%d) join failed = %d",
+                     m, m->thread, pa_thread_get_name(m->thread), pa_thread_is_running(m->thread), ret);
 #else
     pa_thread_join(m->thread);
 #endif
index 62b0ec4..eef02d4 100644 (file)
@@ -33,6 +33,9 @@
 #include <pulse/xmalloc.h>
 #include <pulsecore/atomic.h>
 #include <pulsecore/macro.h>
+#ifdef __TIZEN__
+#include <pulse/util.h>
+#endif
 
 #include "thread.h"
 
@@ -61,6 +64,43 @@ static void thread_free_cb(void *p) {
     }
 }
 
+#ifdef __TIZEN__
+static void dump_thread_attributes(pa_thread *t) {
+    int ret = 0;
+    pthread_attr_t attr;
+    int detachstate = -1;
+    int policy = -1;
+    int inherit = -1;
+
+    pa_assert(t);
+
+    ret = pthread_attr_init(&attr);
+    if (ret != 0) {
+        pa_log_error("failed to init pthread attr, ret=%d", ret);
+        return;
+    }
+
+    ret = pthread_attr_getdetachstate(&attr, &detachstate);
+    if (ret != 0)
+        pa_log_error("failed to get pthread attr detachstate, ret=%d", ret);
+
+    ret = pthread_attr_getschedpolicy(&attr, &policy);
+    if (ret != 0)
+        pa_log_error("failed to get pthread attr sched policy, ret=%d", ret);
+
+    ret = pthread_attr_getinheritsched(&attr, &inherit);
+    if (ret != 0)
+        pa_log_error("failed to get pthread attr inherit sched, ret=%d", ret);
+
+    pa_log_info("thread(%p, %s) : id(%lu), detachstate(%d), policy(%d), inherit(%d)",
+                t, t->name, t->id, detachstate, policy, inherit);
+
+    ret = pthread_attr_destroy(&attr);
+    if (ret != 0)
+        pa_log_error("failed to destroy pthread attr, ret=%d", ret);
+}
+#endif
+
 PA_STATIC_TLS_DECLARE(current_thread, thread_free_cb);
 
 static void* internal_thread_func(void *userdata) {
@@ -77,6 +117,10 @@ static void* internal_thread_func(void *userdata) {
 
     PA_STATIC_TLS_SET(current_thread, t);
 
+#ifdef __TIZEN__
+    dump_thread_attributes(t);
+#endif
+
     pa_atomic_inc(&t->running);
     t->thread_func(t->userdata);
     pa_atomic_sub(&t->running, 2);
@@ -119,7 +163,11 @@ int pa_thread_is_running(pa_thread *t) {
 void pa_thread_free(pa_thread *t) {
     pa_assert(t);
 
+#ifdef __TIZEN__
+    pa_log_info("pa_thread_join(%p, %s) = %d", t, t->name, pa_thread_join(t));
+#else
     pa_thread_join(t);
+#endif
 
     pa_xfree(t->name);
     pa_xfree(t);
@@ -132,6 +180,31 @@ void pa_thread_free_nojoin(pa_thread *t) {
     pa_xfree(t);
 }
 
+#ifdef __TIZEN__
+static int trial_thread_join(pa_thread *t, int retry) {
+    int ret = 0;
+
+    pa_assert(t);
+
+    pa_log_info("thread(%p, %s) joining    : id(%lu), running_ref(%d), joined(%d)",
+                t, t->name, t->id, pa_atomic_load(&t->running), t->joined);
+
+    while ((ret = pthread_join(t->id, NULL)) != 0 && retry-- > 0) {
+        pa_log_warn("  [%2d] thread(%p, %s) failed to join = %d : id(%lu), running_ref(%d), joined(%d)",
+                retry, t, t->name, ret, t->id, pa_atomic_load(&t->running), t->joined);
+        pa_msleep(100);
+    }
+
+    if (ret == 0)
+        t->joined = true;
+
+    pa_log_info("thread(%p, %s) joined = %d : id(%lu), running_ref(%d), joined(%d)",
+                t, t->name, ret, t->id, pa_atomic_load(&t->running), t->joined);
+
+    return ret;
+}
+#endif
+
 int pa_thread_join(pa_thread *t) {
     pa_assert(t);
     pa_assert(t->thread_func);
@@ -139,8 +212,12 @@ int pa_thread_join(pa_thread *t) {
     if (t->joined)
         return -1;
 
+#ifdef __TIZEN__
+    return trial_thread_join(t, 20);
+#else
     t->joined = true;
     return pthread_join(t->id, NULL);
+#endif
 }
 
 pa_thread* pa_thread_self(void) {