[pulseaudio-discuss] [PATCH 2/3] mainloop: Add API to set thread name for threaded mainloop

Arun Raghavan arun.raghavan at collabora.co.uk
Tue May 14 21:43:06 PDT 2013


---
 src/map-file                |  1 +
 src/pulse/thread-mainloop.c | 16 +++++++++++++++-
 src/pulse/thread-mainloop.h |  3 +++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/map-file b/src/map-file
index 91d61c2..21e3abc 100644
--- a/src/map-file
+++ b/src/map-file
@@ -344,6 +344,7 @@ pa_threaded_mainloop_get_retval;
 pa_threaded_mainloop_in_thread;
 pa_threaded_mainloop_lock;
 pa_threaded_mainloop_new;
+pa_threaded_mainloop_set_name;
 pa_threaded_mainloop_signal;
 pa_threaded_mainloop_start;
 pa_threaded_mainloop_stop;
diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c
index aa56a92..6fb31e7 100644
--- a/src/pulse/thread-mainloop.c
+++ b/src/pulse/thread-mainloop.c
@@ -50,6 +50,8 @@ struct pa_threaded_mainloop {
     pa_thread* thread;
     pa_mutex* mutex;
     pa_cond* cond, *accept_cond;
+
+    char *name;
 };
 
 static inline int in_worker(pa_threaded_mainloop *m) {
@@ -106,6 +108,7 @@ pa_threaded_mainloop *pa_threaded_mainloop_new(void) {
     m->cond = pa_cond_new();
     m->accept_cond = pa_cond_new();
     m->thread = NULL;
+    m->name = NULL;
 
     pa_mainloop_set_poll_func(m->real_mainloop, poll_func, m->mutex);
 
@@ -132,6 +135,7 @@ void pa_threaded_mainloop_free(pa_threaded_mainloop* m) {
     pa_cond_free(m->cond);
     pa_cond_free(m->accept_cond);
 
+    pa_xfree (m->name);
     pa_xfree(m);
 }
 
@@ -140,7 +144,7 @@ int pa_threaded_mainloop_start(pa_threaded_mainloop *m) {
 
     pa_assert(!m->thread || !pa_thread_is_running(m->thread));
 
-    if (!(m->thread = pa_thread_new("threaded-ml", thread, m)))
+    if (!(m->thread = pa_thread_new(m->name ? m->name : "threaded-ml", thread, m)))
         return -1;
 
     return 0;
@@ -239,3 +243,13 @@ int pa_threaded_mainloop_in_thread(pa_threaded_mainloop *m) {
 
     return m->thread && pa_thread_self() == m->thread;
 }
+
+void pa_threaded_mainloop_set_name(pa_threaded_mainloop *m, const char *name) {
+    pa_assert(m);
+    pa_assert(name);
+
+    m->name = pa_xstrdup(name);
+
+    if (m->thread)
+        pa_thread_set_name(m->thread, m->name);
+}
diff --git a/src/pulse/thread-mainloop.h b/src/pulse/thread-mainloop.h
index ff166f8..6933ec5 100644
--- a/src/pulse/thread-mainloop.h
+++ b/src/pulse/thread-mainloop.h
@@ -311,6 +311,9 @@ pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m);
 /** Returns non-zero when called from within the event loop thread. \since 0.9.7 */
 int pa_threaded_mainloop_in_thread(pa_threaded_mainloop *m);
 
+/** Sets the name of the thread. \since 4.0 */
+void pa_threaded_mainloop_set_name(pa_threaded_mainloop *m, const char *name);
+
 PA_C_DECL_END
 
 #endif
-- 
1.8.2.1



More information about the pulseaudio-discuss mailing list