[pulseaudio-commits] r1688 - in /branches/lennart/src/pulsecore: rtsig.c rtsig.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Aug 21 17:23:34 PDT 2007


Author: lennart
Date: Wed Aug 22 02:23:33 2007
New Revision: 1688

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1688&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add facility for managing realtime signals

Added:
    branches/lennart/src/pulsecore/rtsig.c
    branches/lennart/src/pulsecore/rtsig.h

Added: branches/lennart/src/pulsecore/rtsig.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
rtsig.c?rev=3D1688&root=3Dpulseaudio&view=3Dauto
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/rtsig.c (added)
+++ branches/lennart/src/pulsecore/rtsig.c Wed Aug 22 02:23:33 2007
@@ -1,0 +1,111 @@
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-2006 Lennart Poettering
+  Copyright 2006 Pierre Ossman <ossman at cendio.se> for Cendio AB
+
+  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
+  Lesser 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 <signal.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/flist.h>
+#include <pulsecore/once.h>
+#include <pulsecore/thread.h>
+
+#include "rtsig.h"
+
+static void _free_rtsig(void *p) {
+    pa_rtsig_put(PA_PTR_TO_INT(p));
+}
+
+PA_STATIC_FLIST_DECLARE(rtsig_flist, pa_make_power_of_two(SIGRTMAX-SIGRTMI=
N+1), NULL);
+PA_STATIC_TLS_DECLARE(rtsig_tls, _free_rtsig);
+
+static pa_atomic_t rtsig_current =3D PA_ATOMIC_INIT(-1);
+
+static int rtsig_start =3D -1, rtsig_end =3D -1;
+
+int pa_rtsig_get(void) {
+    void *p;
+    int sig;
+    =

+    if ((p =3D pa_flist_pop(PA_STATIC_FLIST_GET(rtsig_flist))))
+        return PA_PTR_TO_INT(p);
+
+    sig =3D pa_atomic_inc(&rtsig_current);
+
+    pa_assert(sig >=3D SIGRTMIN);
+    pa_assert(sig >=3D rtsig_start);
+    =

+    if (sig > rtsig_end) {
+        pa_atomic_dec(&rtsig_current);
+        return -1;
+    }
+
+    return sig;
+}
+
+int pa_rtsig_get_for_thread(void) {
+    int sig;
+    void *p;
+
+    if ((p =3D pa_tls_get(PA_STATIC_TLS_GET(rtsig_tls))))
+        return PA_PTR_TO_INT(p);
+    =

+    if ((sig =3D pa_rtsig_get()) < 0)
+        return -1;
+
+    pa_tls_set(PA_STATIC_TLS_GET(rtsig_tls), PA_INT_TO_PTR(sig));
+    return sig;
+}
+
+void pa_rtsig_put(int sig) {
+    pa_assert(sig >=3D rtsig_start);
+    pa_assert(sig <=3D rtsig_end);
+
+    pa_assert_se(pa_flist_push(PA_STATIC_FLIST_GET(rtsig_flist), PA_INT_TO=
_PTR(sig)) >=3D 0);
+}
+
+void pa_rtsig_configure(int start, int end) {
+    int s;
+    sigset_t ss;
+
+    pa_assert(pa_atomic_load(&rtsig_current) =3D=3D -1);
+
+    pa_assert(SIGRTMIN <=3D start);
+    pa_assert(start <=3D end);
+    pa_assert(end <=3D SIGRTMAX);
+
+    rtsig_start =3D start;
+    rtsig_end =3D end;
+
+    sigemptyset(&ss);
+    =

+    for (s =3D rtsig_start; s <=3D rtsig_end; s++)
+        pa_assert_se(sigaddset(&ss, s) =3D=3D 0);
+    =

+    pa_assert(pthread_sigmask(SIG_BLOCK, &ss, NULL) =3D=3D 0);
+    =

+    pa_atomic_store(&rtsig_current, rtsig_start);
+}

Added: branches/lennart/src/pulsecore/rtsig.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
rtsig.h?rev=3D1688&root=3Dpulseaudio&view=3Dauto
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/rtsig.h (added)
+++ branches/lennart/src/pulsecore/rtsig.h Wed Aug 22 02:23:33 2007
@@ -1,0 +1,44 @@
+#ifndef foopulsertsighfoo
+#define foopulsertsighfoo
+
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-2006 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.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
+  Lesser 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 <poll.h>
+#include <sys/types.h>
+
+/* Return the next unused POSIX Realtime signals */
+int pa_rtsig_get(void);
+
+/* If not called before in the current thread, return the next unused
+ * rtsig, and install it in a TLS region and give it up automatically
+ * when the thread shuts down */
+int pa_rtsig_get_for_thread(void);
+
+/* Give an rtsig back. */
+void pa_rtsig_put(int sig);
+
+/* Block all RT signals */
+void pa_rtsig_configure(int start, int end);
+
+#endif




More information about the pulseaudio-commits mailing list