[pulseaudio-discuss] More patches for better OS X support

Colin Guthrie gmane at colin.guthr.ie
Sat Apr 23 10:21:22 PDT 2011


'Twas brillig, and Colin Guthrie at 23/04/11 17:51 did gyre and gimble:
> 'Twas brillig, and Daniel Mack at 22/04/11 13:27 did gyre and gimble:
>> Here goes another round of patches for PulseAudio on OS X. Most patches
>> are small, and none of them should affect other systems than OSX.
> 
> Thanks as always Daniel. I grabbed all the patches but tweaked the
> commit messages a little bit, so you'll need a rebase for the next
> batch. Hope that's OK :)

Oh, forgot to mention that I had to tweak the code a bit too (squashed
into your changes)... two problems I found:


1. A simple typo:

diff --git a/src/pulse/util.c b/src/pulse/util.c
index e44a864..48ccf29 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -226,7 +226,7 @@ char *pa_get_binary_name(char *s, size_t l) {
     }
 #endif

-#if OS_IS_DARWIN
+#ifdef OS_IS_DARWIN
     {
         int mib[] = { CTL_KERN, KERN_PROCARGS, getpid(), 0 };
         size_t len, nmib = (sizeof(mib) / sizeof(mib[0])) - 1;



2. I found that HAVE_PTHREAD_SETNAME_NP was indeed defined on my system,
but that it takes two arguments here, not one. This caused build errors
for me.

Thus I made the following change:

diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c
index ae73267..58bcb72 100644
--- a/src/pulsecore/thread-posix.c
+++ b/src/pulsecore/thread-posix.c
@@ -71,10 +71,10 @@ static void* internal_thread_func(void *userdata) {
     pa_thread *t = userdata;
     pa_assert(t);

-#ifdef HAVE_PTHREAD_SETNAME_NP
-    pthread_setname_np(t->name);
-#elif defined(__linux__)
+#ifdef __linux__
     prctl(PR_SET_NAME, t->name);
+#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
+    pthread_setname_np(t->name);
 #endif

     t->id = pthread_self();
@@ -177,22 +177,17 @@ void pa_thread_set_name(pa_thread *t, const char
*name) {
     pa_xfree(t->name);
     t->name = pa_xstrdup(name);

-#ifdef HAVE_PTHREAD_SETNAME_NP
-    pthread_setname_np(name);
-#elif defined(__linux__)
+#ifdef __linux__
     prctl(PR_SET_NAME, name);
+#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
+    pthread_setname_np(name);
 #endif
 }

 const char *pa_thread_get_name(pa_thread *t) {
     pa_assert(t);

-#ifdef HAVE_PTHREAD_GETNAME_NP
-    if (!t->name) {
-        t->name = pa_xmalloc0(17);
-        pthread_getname_np(t->id, t->name, 16);
-    }
-#elif defined(__linux__)
+#ifdef __linux__
     if (!t->name) {
         t->name = pa_xmalloc(17);

@@ -203,6 +198,11 @@ const char *pa_thread_get_name(pa_thread *t) {
             t->name = NULL;
         }
     }
+#elif defined(HAVE_PTHREAD_GETNAME_NP) && defined(OS_IS_DARWIN)
+    if (!t->name) {
+        t->name = pa_xmalloc0(17);
+        pthread_getname_np(t->id, t->name, 16);
+    }
 #endif

     return t->name;


This should still work for you on OSX (if not, then I apologise!). I
added the OS_IS_DARWIN bit as the API for pthread_setname_np does not
appear to be totally stable (two args here, and I presume just one arg
on OSX).

I figured this may actually break windows stuff if it also has the
two-arg version, hence the additional check. Hope that makes sense.

Of course it may be possible to use pthread_setname_np on linux too
(albeit with it's two arg variant...) which could simplify the code a bit...

Both changes squashed into your commits.

Col



-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]




More information about the pulseaudio-discuss mailing list