[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.13-382-g54dad91

Lennart Poettering gitmailer-noreply at 0pointer.de
Fri Jan 23 15:13:34 PST 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  db27c6347ebe3316bb5f80518c6cc86eea67779b (commit)

- Log -----------------------------------------------------------------
54dad91... use pa_log_ratelimit() at a few places
77c4ccf... add pa_log_rate_limit()
3dfe70c... add generic rate limiting implementation
e960125... add support for static mutexes
-----------------------------------------------------------------------

Summary of changes:
 src/Makefile.am                |    1 +
 src/modules/alsa/alsa-sink.c   |    6 ++--
 src/modules/alsa/alsa-source.c |    6 ++--
 src/pulsecore/log.c            |    8 ++++
 src/pulsecore/log.h            |    2 +
 src/pulsecore/mutex-posix.c    |   20 +++++++++++
 src/pulsecore/mutex.h          |    7 ++++
 src/pulsecore/ratelimit.c      |   75 ++++++++++++++++++++++++++++++++++++++++
 src/pulsecore/ratelimit.h      |   46 ++++++++++++++++++++++++
 9 files changed, 165 insertions(+), 6 deletions(-)
 create mode 100644 src/pulsecore/ratelimit.c
 create mode 100644 src/pulsecore/ratelimit.h

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

commit e9601250110decc8f4323c76be8549acff091966
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 23 23:57:47 2009 +0100

    add support for static mutexes

diff --git a/src/pulsecore/mutex-posix.c b/src/pulsecore/mutex-posix.c
index 35465b7..c3ead97 100644
--- a/src/pulsecore/mutex-posix.c
+++ b/src/pulsecore/mutex-posix.c
@@ -138,3 +138,23 @@ int pa_cond_wait(pa_cond *c, pa_mutex *m) {
 
     return pthread_cond_wait(&c->cond, &m->mutex);
 }
+
+pa_mutex* pa_static_mutex_get(pa_static_mutex *s, pa_bool_t recursive, pa_bool_t inherit_priority) {
+    pa_mutex *m;
+
+    pa_assert(s);
+
+    /* First, check if already initialized and short cut */
+    if ((m = pa_atomic_ptr_load(&s->ptr)))
+        return m;
+
+    /* OK, not initialized, so let's allocate, and fill in */
+    m = pa_mutex_new(recursive, inherit_priority);
+    if ((pa_atomic_ptr_cmpxchg(&s->ptr, NULL, m)))
+        return m;
+
+    /* Him, filling in failed, so someone else must have filled in
+     * already */
+    pa_assert_se(m = pa_atomic_ptr_load(&s->ptr));
+    return m;
+}
diff --git a/src/pulsecore/mutex.h b/src/pulsecore/mutex.h
index 36e1d63..8e0b1f2 100644
--- a/src/pulsecore/mutex.h
+++ b/src/pulsecore/mutex.h
@@ -23,6 +23,7 @@
 ***/
 
 #include <pulsecore/macro.h>
+#include <pulsecore/atomic.h>
 
 typedef struct pa_mutex pa_mutex;
 
@@ -45,4 +46,10 @@ void pa_cond_free(pa_cond *c);
 void pa_cond_signal(pa_cond *c, int broadcast);
 int pa_cond_wait(pa_cond *c, pa_mutex *m);
 
+typedef struct pa_static_mutex {
+    pa_atomic_ptr_t ptr;
+} pa_static_mutex;
+
+pa_mutex* pa_static_mutex_get(pa_static_mutex *m, pa_bool_t recursive, pa_bool_t inherit_priority);
+
 #endif

commit 3dfe70cf7887cfb288e4423358350ef4511506b5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 23 23:58:36 2009 +0100

    add generic rate limiting implementation

diff --git a/src/Makefile.am b/src/Makefile.am
index 24623d3..e27bfba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -533,6 +533,7 @@ libpulsecommon_ at PA_MAJORMINORMICRO@_la_SOURCES = \
 		pulsecore/llist.h \
 		pulsecore/lock-autospawn.c pulsecore/lock-autospawn.h \
 		pulsecore/log.c pulsecore/log.h \
+		pulsecore/ratelimit.c pulsecore/ratelimit.h \
 		pulsecore/macro.h pulsecore/vector.h \
 		pulsecore/mcalign.c pulsecore/mcalign.h \
 		pulsecore/memblock.c pulsecore/memblock.h \
diff --git a/src/pulsecore/ratelimit.c b/src/pulsecore/ratelimit.c
new file mode 100644
index 0000000..8ce7857
--- /dev/null
+++ b/src/pulsecore/ratelimit.c
@@ -0,0 +1,75 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  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 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 <pulsecore/rtclock.h>
+#include <pulsecore/log.h>
+#include <pulsecore/mutex.h>
+
+#include "ratelimit.h"
+
+static pa_static_mutex mutex;
+
+/* Modelled after Linux' lib/ratelimit.c by Dave Young
+ * <hidave.darkstar at gmail.com>, which is licensed GPLv2. */
+
+pa_bool_t pa_ratelimit_test(pa_ratelimit *r) {
+    pa_usec_t now;
+    pa_mutex *m;
+
+    now = pa_rtclock_usec();
+
+    m = pa_static_mutex_get(&mutex, FALSE, FALSE);
+    pa_mutex_lock(m);
+
+    pa_assert(r);
+    pa_assert(r->interval > 0);
+    pa_assert(r->burst > 0);
+
+    if (r->begin <= 0 ||
+        r->begin + r->interval < now) {
+
+        if (r->n_missed > 0)
+            pa_log_warn("%u events suppressed", r->n_missed);
+
+        r->begin = now;
+
+        /* Reset counters */
+        r->n_printed = 0;
+        r->n_missed = 0;
+        goto good;
+    }
+
+    if (r->n_printed <= r->burst)
+        goto good;
+
+    r->n_missed++;
+    pa_mutex_unlock(m);
+    return FALSE;
+
+good:
+    r->n_printed++;
+    pa_mutex_unlock(m);
+    return TRUE;
+}
diff --git a/src/pulsecore/ratelimit.h b/src/pulsecore/ratelimit.h
new file mode 100644
index 0000000..e652c52
--- /dev/null
+++ b/src/pulsecore/ratelimit.h
@@ -0,0 +1,46 @@
+#ifndef foopulsecoreratelimithfoo
+#define foopulsecoreratelimithfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  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 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.
+***/
+
+#include <pulse/sample.h>
+#include <pulsecore/macro.h>
+
+typedef struct pa_ratelimit {
+    const pa_usec_t interval;
+    const unsigned burst;
+    unsigned n_printed, n_missed;
+    pa_usec_t begin;
+} pa_ratelimit;
+
+#define PA_DEFINE_RATELIMIT(_name, _interval, _burst)   \
+    pa_ratelimit _name = {                              \
+        .interval = _interval,                          \
+        .burst = _burst,                                \
+        .n_printed = 0,                                 \
+        .n_missed = 0,                                  \
+        .begin = 0                                      \
+    }
+
+pa_bool_t pa_ratelimit_test(pa_ratelimit *r);
+
+#endif

commit 77c4ccfcaff95f25be373e036999869746ed81a7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 23 23:58:57 2009 +0100

    add pa_log_rate_limit()

diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c
index adf2f11..9a7f7ca 100644
--- a/src/pulsecore/log.c
+++ b/src/pulsecore/log.c
@@ -47,6 +47,7 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/rtclock.h>
 #include <pulsecore/once.h>
+#include <pulsecore/ratelimit.h>
 
 #include "log.h"
 
@@ -375,3 +376,10 @@ void pa_log_level(pa_log_level_t level, const char *format, ...) {
     pa_log_levelv_meta(level, NULL, 0, NULL, format, ap);
     va_end(ap);
 }
+
+pa_bool_t pa_log_ratelimit(void) {
+    /* Not more than 10 messages every 5s */
+    static PA_DEFINE_RATELIMIT(ratelimit, 5 * PA_USEC_PER_SEC, 10);
+
+    return pa_ratelimit_test(&ratelimit);
+}
diff --git a/src/pulsecore/log.h b/src/pulsecore/log.h
index 3d66e90..77adb79 100644
--- a/src/pulsecore/log.h
+++ b/src/pulsecore/log.h
@@ -109,4 +109,6 @@ LOG_FUNC(error, PA_LOG_ERROR)
 
 #define pa_log pa_log_error
 
+pa_bool_t pa_log_ratelimit(void);
+
 #endif

commit 54dad91f079a88f7f7dfb17692ff09af70d30e2e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jan 24 00:12:12 2009 +0100

    use pa_log_ratelimit() at a few places

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index f092b5d..94b289f 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -251,7 +251,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
 
         if (PA_UNLIKELY(n <= u->hwbuf_unused_frames)) {
 
-            if (polled)
+            if (polled && pa_log_ratelimit())
                 pa_log("ALSA woke us up to write new data to the device, but there was actually nothing to write! "
                        "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
                        "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail_update() returned 0.");
@@ -374,7 +374,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
 
         if (PA_UNLIKELY(n <= u->hwbuf_unused_frames)) {
 
-            if (polled)
+            if (polled && pa_log_ratelimit())
                 pa_log("ALSA woke us up to write new data to the device, but there was actually nothing to write! "
                        "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
                        "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail_update() returned 0.");
@@ -1194,7 +1194,7 @@ static void thread_func(void *userdata) {
                 u->since_start = 0;
             }
 
-            if (revents && u->use_tsched)
+            if (revents && u->use_tsched && pa_log_ratelimit())
                 pa_log_debug("Wakeup from ALSA!%s%s", (revents & POLLIN) ? " INPUT" : "", (revents & POLLOUT) ? " OUTPUT" : "");
         } else
             revents = 0;
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 0c4e5bc..b8ad2e2 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -238,7 +238,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
 
         if (PA_UNLIKELY(n <= 0)) {
 
-            if (polled)
+            if (polled && pa_log_ratelimit())
                 pa_log("ALSA woke us up to read new data from the device, but there was actually nothing to read! "
                        "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
                        "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail_update() returned 0.");
@@ -346,7 +346,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
 
         if (PA_UNLIKELY(n <= 0)) {
 
-            if (polled)
+            if (polled && pa_log_ratelimit())
                 pa_log("ALSA woke us up to read new data from the device, but there was actually nothing to read! "
                        "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. "
                        "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail_update() returned 0.");
@@ -1029,7 +1029,7 @@ static void thread_func(void *userdata) {
                 snd_pcm_start(u->pcm_handle);
             }
 
-            if (revents && u->use_tsched)
+            if (revents && u->use_tsched && pa_log_ratelimit())
                 pa_log_debug("Wakeup from ALSA!%s%s", (revents & POLLIN) ? " INPUT" : "", (revents & POLLOUT) ? " OUTPUT" : "");
         } else
             revents = 0;

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list