mainloop: Add API to set thread name for threaded mainloop

This commit is contained in:
Arun Raghavan 2013-05-15 09:37:45 +05:30
parent 1b0136be44
commit 8d129977ca
3 changed files with 19 additions and 1 deletions

View 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;

View 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);
}

View 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