[pulseaudio-discuss] [PATCH 1/2] thread-posix: remove duplicate code for setting thread name

Lu Guanqun guanqun.lu at intel.com
Wed Aug 10 08:12:06 PDT 2011


According to the principle of DRY (don't repeat yourself), remove the code for
setting thread name in thread-posix.c.

Signed-off-by: Lu Guanqun <guanqun.lu at intel.com>
---
 src/pulsecore/thread-posix.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c
index 3f4ae5c..81ae98d 100644
--- a/src/pulsecore/thread-posix.c
+++ b/src/pulsecore/thread-posix.c
@@ -65,15 +65,19 @@ static void thread_free_cb(void *p) {
 
 PA_STATIC_TLS_DECLARE(current_thread, thread_free_cb);
 
+static void pa_thread_set_name_raw(const char *name) {
+#ifdef __linux__
+    prctl(PR_SET_NAME, name);
+#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
+    pthread_setname_np(name);
+#endif
+}
+
 static void* internal_thread_func(void *userdata) {
     pa_thread *t = userdata;
     pa_assert(t);
 
-#ifdef __linux__
-    prctl(PR_SET_NAME, t->name);
-#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
-    pthread_setname_np(t->name);
-#endif
+    pa_thread_set_name_raw(t->name);
 
     t->id = pthread_self();
 
@@ -175,11 +179,7 @@ void pa_thread_set_name(pa_thread *t, const char *name) {
     pa_xfree(t->name);
     t->name = pa_xstrdup(name);
 
-#ifdef __linux__
-    prctl(PR_SET_NAME, name);
-#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
-    pthread_setname_np(name);
-#endif
+    pa_thread_set_name_raw(name);
 }
 
 const char *pa_thread_get_name(pa_thread *t) {



More information about the pulseaudio-discuss mailing list