]> code.delx.au - pulseaudio/commitdiff
mainloop: Add API to set thread name for threaded mainloop
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 15 May 2013 04:07:45 +0000 (09:37 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 3 Jun 2013 19:08:43 +0000 (00:38 +0530)
src/map-file
src/pulse/thread-mainloop.c
src/pulse/thread-mainloop.h

index 955b295046c3dde434e11600c742b54b49e8f7be..90c8ea2b2be530ba34654b41165e0eb37be44641 100644 (file)
@@ -343,6 +343,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;
index aa56a9209cee84e836a68563b10a0e222555f814..a05d959808838855d6dd0a04879ca079c5300842 100644 (file)
@@ -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);
+}
index 34370012e33f9e8a5d8edf9c8cba2a49e67c9b28..689336d7ab53c26722d9f60b310b6176feee3647 100644 (file)
@@ -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