[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.19-213-g542fa46

Lennart Poettering gitmailer-noreply at 0pointer.de
Fri Oct 30 17:33:56 PDT 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  65e8078a3bba6360f7918b2a721510d78826eece (commit)

- Log -----------------------------------------------------------------
542fa46 Mac OS X: add semaphore implementation
b04fe9b Wrap clock_gettime and friends
-----------------------------------------------------------------------

Summary of changes:
 src/pulsecore/core-rtclock.c                       |   54 +++++++++++++++++--
 .../{semaphore-win32.c => semaphore-osx.c}         |   20 ++++----
 2 files changed, 58 insertions(+), 16 deletions(-)
 copy src/pulsecore/{semaphore-win32.c => semaphore-osx.c} (67%)

-----------------------------------------------------------------------

commit b04fe9b516160f92d016a8bb81a431c74cac2ecd
Author: Daniel Mack <daniel at caiaq.de>
Date:   Mon Oct 19 12:45:30 2009 +0200

    Wrap clock_gettime and friends
    
    On Wed, Sep 16, 2009 at 11:48:58PM +0200, Lennart Poettering wrote:
    > On Wed, 16.09.09 15:15, Daniel Mack (daniel at caiaq.de) wrote:
    >
    > > From: Kim Lester <kim at dfusion.com.au>
    > >
    > > OS X does not define clockid_t or clock_gettime() and friends.
    > > Add a wrapper to fix this.
    >
    > Hmpf. I am not particularly happy with this. This adds a lot of
    > unnecessary compat code. We don't actually need implementations of
    > clock_getres(). All we need is some kind of check whether system
    > timers are accurate or whether they are rounded up to scheduling
    > slices. On Linux we do that check with clock_getres(), but all the
    > information it returns is actually not intertesting at all. We just
    > check if this is below some trheshold, that's all.
    >
    > clock_settime() we don't use at all! We shouldn't carry compat code
    > for that.
    >
    > And clock_gettime we don't really need either. We need some kind of
    > accurate system timers (preferably monotonic), and on Linux we use
    > clock_gettime() for that. But we already have a fallback there for
    > gettimeofday().
    >
    > Or in other words, the current APIs pa_rtclock_get(),
    > pa_rtclock_hrtimer() is supposed to be the abstract API that has
    > different backends on different systems. I'd very much prefer if any
    > MacOS specific code would simply be plugged in there instead of
    > creating various new abstraction interfaces!
    
    Ok - what about the version below? I don't particularily like the
    
    Daniel
    
    >From 9f0a051953ec354ccdb8aa44a9845c408b26ae0b Mon Sep 17 00:00:00 2001
    From: Kim Lester <kim at dfusion.com.au>
    Date: Wed, 16 Sep 2009 14:40:01 +0800
    Subject: [PATCH] Implement pa_rtclock_get() and pa_rtclock_hrtimer() for Darwin
    
    OS X does not define clockid_t or clock_gettime() and friends.
    Add wrappers to fix this. Based on a patch from Kim Lester
    <kim at dfusion.com.au>.

diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c
index 1420470..4fe0a47 100644
--- a/src/pulsecore/core-rtclock.c
+++ b/src/pulsecore/core-rtclock.c
@@ -33,6 +33,12 @@
 #include <sys/prctl.h>
 #endif
 
+#ifdef OS_IS_DARWIN
+#include <CoreServices/CoreServices.h>
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+#endif
+
 #include <pulse/timeval.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/core-error.h>
@@ -47,7 +53,8 @@ pa_usec_t pa_rtclock_age(const struct timeval *tv) {
 }
 
 struct timeval *pa_rtclock_get(struct timeval *tv) {
-#ifdef HAVE_CLOCK_GETTIME
+
+#if defined(HAVE_CLOCK_GETTIME)
     struct timespec ts;
 
 #ifdef CLOCK_MONOTONIC
@@ -59,7 +66,7 @@ struct timeval *pa_rtclock_get(struct timeval *tv) {
             no_monotonic = TRUE;
 
     if (no_monotonic)
-#endif
+#endif /* CLOCK_MONOTONIC */
         pa_assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
 
     pa_assert(tv);
@@ -69,7 +76,30 @@ struct timeval *pa_rtclock_get(struct timeval *tv) {
 
     return tv;
 
-#else /* HAVE_CLOCK_GETTIME */
+#elif defined(OS_IS_DARWIN)
+    static mach_timebase_info_data_t   tbi;
+    uint64_t nticks;
+    uint64_t time_nsec;
+
+    /* Refer Apple ADC QA1398
+       Also: http://devworld.apple.com/documentation/Darwin/Conceptual/KernelProgramming/services/services.html
+
+       Note: argument is timespec NOT timeval (timespec uses nsec, timeval uses usec)
+    */
+
+    /* try and be a mite efficient - maybe I should keep the N/D as a float !? */
+    if (tbi.denom == 0)
+        mach_timebase_info(&tbi);
+
+    nticks = mach_absolute_time();
+    time_nsec = nticks * tbi.numer / tbi.denom; // see above
+
+    tv->tv_sec = time_nsec / PA_NSEC_PER_SEC;
+    tv->tv_usec = time_nsec / PA_NSEC_PER_USEC;
+
+    return tv;
+
+#else /* OS_IS_DARWIN */
 
     return pa_gettimeofday(tv);
 
@@ -77,19 +107,30 @@ struct timeval *pa_rtclock_get(struct timeval *tv) {
 }
 
 pa_bool_t pa_rtclock_hrtimer(void) {
-#ifdef HAVE_CLOCK_GETTIME
+
+#if defined(HAVE_CLOCK_GETTIME)
     struct timespec ts;
 
 #ifdef CLOCK_MONOTONIC
+
     if (clock_getres(CLOCK_MONOTONIC, &ts) >= 0)
         return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC);
-#endif
+#endif /* CLOCK_MONOTONIC */
 
     pa_assert_se(clock_getres(CLOCK_REALTIME, &ts) == 0);
     return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC);
 
-#else /* HAVE_CLOCK_GETTIME */
+#elif defined (OS_IS_DARWIN)
+    mach_timebase_info_data_t tbi;
+    uint64_t time_nsec;
+
+    mach_timebase_info(&tbi);
 
+    /* nsec = nticks * (N/D) - we want 1 tick == resolution !? */
+    time_nsec = tbi.numer / tbi.denom;
+    return time_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC);
+
+#else /* OS_IS_DARWIN */
     return FALSE;
 
 #endif
@@ -98,6 +139,7 @@ pa_bool_t pa_rtclock_hrtimer(void) {
 #define TIMER_SLACK_NS (int) ((500 * PA_NSEC_PER_USEC))
 
 void pa_rtclock_hrtimer_enable(void) {
+
 #ifdef PR_SET_TIMERSLACK
     int slack_ns;
 

commit 542fa468c26c5035485dc73392c57c222183b510
Author: Daniel Mack <daniel at caiaq.de>
Date:   Mon Oct 19 12:48:00 2009 +0200

    Mac OS X: add semaphore implementation
    
    On Wed, Sep 16, 2009 at 11:57:04PM +0200, Lennart Poettering wrote:
    > On Wed, 16.09.09 15:15, Daniel Mack (daniel at caiaq.de) wrote:
    >
    > > +    s = pa_xnew(pa_semaphore, 1);
    > > +    MPCreateSemaphore(UINT_MAX, value, &(s->sema));
    > > +    pa_assert(s->sema != 0);
    >
    > Hmm, I'd prefer if the ret val of MPCreateSemaphore() would be checked
    > here.
    >
    > Also I find it a bit weird checking for s->sema, though not
    > initializing it to 0 in the beginning. If the call actually failed,
    > then the assert will check uninitialized memory. Also, comparing
    > pointers with 0 sucks. That should be NULL.
    >
    > Given that this can not realisitically fail, only in OOM or OOM-like
    > situations in which case we abort anyway it mght be enough just writing:
    >
    > pa_assert_se(MPCreateSemaphore(UINT_MAX, value, &s->sema) == 0);
    >
    > (Assuming that success is signalled by retval == 0 on MacOSX)
    >
    > > +void pa_semaphore_free(pa_semaphore *s) {
    > > +    pa_assert(s);
    > > +    MPDeleteSemaphore(s->sema);
    >
    > Same here.
    >
    > > +    pa_xfree(s);
    > > +}
    > > +
    > > +void pa_semaphore_post(pa_semaphore *s) {
    > > +    pa_assert(s);
    > > +    MPSignalSemaphore(s->sema);
    >
    > And here.
    >
    > > +}
    > > +
    > > +void pa_semaphore_wait(pa_semaphore *s) {
    > > +    pa_assert(s);
    > > +    /* should probably check return value (-ve is error), noErr is ok. */
    > > +    MPWaitOnSemaphore(s->sema, kDurationForever);
    >
    > And here.
    
    Ok, done. See the patch below.
    
    Daniel
    
    >From 26df2fbae6d9215a3ae084876fb5f79e4d9cf4f0 Mon Sep 17 00:00:00 2001
    From: Kim Lester <kim at dfusion.com.au>
    Date: Wed, 16 Sep 2009 09:23:39 +0800
    Subject: [PATCH] Mac OS X: add semaphore implementation

diff --git a/src/pulsecore/semaphore-osx.c b/src/pulsecore/semaphore-osx.c
new file mode 100644
index 0000000..73f4355
--- /dev/null
+++ b/src/pulsecore/semaphore-osx.c
@@ -0,0 +1,63 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Kim Lester <kim at dfusion.com.au>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Multiprocessing.h>
+
+#include <pulse/xmalloc.h>
+#include <pulsecore/macro.h>
+
+#include "semaphore.h"
+
+struct pa_semaphore
+{
+    MPSemaphoreID sema;
+};
+
+pa_semaphore* pa_semaphore_new(unsigned int value) {
+    /* NOTE: Can't assume boolean - ie value = 0,1, so use UINT_MAX (boolean more efficient ?) */
+    pa_semaphore *s;
+
+    s = pa_xnew(pa_semaphore, 1);
+    pa_assert_se(MPCreateSemaphore(UINT_MAX, value, &s->sema) == 0);
+
+    return s;
+}
+
+void pa_semaphore_free(pa_semaphore *s) {
+    pa_assert(s);
+    pa_assert_se(MPDeleteSemaphore(s->sema) == 0);
+    pa_xfree(s);
+}
+
+void pa_semaphore_post(pa_semaphore *s) {
+    pa_assert(s);
+    pa_assert_se(MPSignalSemaphore(s->sema) == 0);
+}
+
+void pa_semaphore_wait(pa_semaphore *s) {
+    pa_assert(s);
+    /* should probably check return value (-ve is error), noErr is ok. */
+    pa_assert_se(MPWaitOnSemaphore(s->sema, kDurationForever) == 0);
+}

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list