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
}
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;
}
#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
#include <pulse/xmalloc.h>
#include <pulsecore/atomic.h>
#include <pulsecore/macro.h>
+#ifdef __TIZEN__
+#include <pulse/util.h>
+#endif
#include "thread.h"
}
}
+#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) {
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);
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);
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);
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) {