[pulseaudio-commits] r1622 - in /branches/lennart/src: Makefile.am pulsecore/thread-mq.c pulsecore/thread-mq.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Aug 10 15:01:18 PDT 2007


Author: lennart
Date: Sat Aug 11 00:01:17 2007
New Revision: 1622

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1622&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Wrap two pa_asyncmsq in a new pa_thread_mq object for bidirectional, lock-f=
ree communication between a main loop and a thread

Added:
    branches/lennart/src/pulsecore/thread-mq.c
    branches/lennart/src/pulsecore/thread-mq.h   (with props)
Modified:
    branches/lennart/src/Makefile.am

Modified: branches/lennart/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/Makefile.a=
m?rev=3D1622&root=3Dpulseaudio&r1=3D1621&r2=3D1622&view=3Ddiff
=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/Makefile.am (original)
+++ branches/lennart/src/Makefile.am Sat Aug 11 00:01:17 2007
@@ -662,6 +662,7 @@
 		pulsecore/flist.c pulsecore/flist.h \
 		pulsecore/asyncmsgq.c pulsecore/asyncmsgqq.h \
 		pulsecore/asyncq.c pulsecore/asyncq.h \
+		pulsecore/thread-mq.c pulsecore/thread-mq.h \
 		pulsecore/fdsem.c pulsecore/fdsem.h \
 		pulsecore/object.c pulsecore/object.h \
 		pulsecore/msgobject.c pulsecore/msgobject.h \

Added: branches/lennart/src/pulsecore/thread-mq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
thread-mq.c?rev=3D1622&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/thread-mq.c (added)
+++ branches/lennart/src/pulsecore/thread-mq.c Sat Aug 11 00:01:17 2007
@@ -1,0 +1,119 @@
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 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.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/atomic.h>
+#include <pulsecore/once.h>
+#include <pulsecore/log.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/semaphore.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/flist.h>
+
+#include "thread-mq.h"
+
+static pa_once once =3D PA_ONCE_INIT;
+static pa_tls *tls;
+
+static void asyncmsgq_cb(pa_mainloop_api*api, pa_io_event* e, int fd, pa_i=
o_event_flags_t events, void *userdata) {
+    pa_thread_mq *q =3D userdata;
+
+    pa_assert(pa_asyncmsgq_get_fd(q->outq) =3D=3D fd);
+    pa_assert(events =3D=3D PA_IO_EVENT_INPUT);
+
+    pa_asyncmsgq_after_poll(q->outq);
+
+    for (;;) {
+        pa_msgobject *object;
+        int code;
+        void *data;
+        int64_t offset;
+        pa_memchunk chunk;
+
+        /* Check whether there is a message for us to process */
+        while (pa_asyncmsgq_get(q->outq, &object, &code, &data, &offset, &=
chunk, 0) =3D=3D 0) {
+            int ret;
+
+            ret =3D pa_asyncmsgq_dispatch(object, code, data, offset, &chu=
nk);
+            pa_asyncmsgq_done(q->outq, ret);
+        }
+
+        if (pa_asyncmsgq_before_poll(q->outq) =3D=3D 0)
+            break;
+    }
+}
+
+void pa_thread_mq_init(pa_thread_mq *q, pa_mainloop_api *mainloop) {
+    pa_assert(q);
+    pa_assert(mainloop);
+
+    q->mainloop =3D mainloop;
+    pa_assert_se(q->inq =3D pa_asyncmsgq_new(0));
+    pa_assert_se(q->outq =3D pa_asyncmsgq_new(0));
+    =

+    pa_assert_se(pa_asyncmsgq_before_poll(q->outq) =3D=3D 0);
+    pa_assert_se(q->io_event =3D mainloop->io_new(mainloop, pa_asyncmsgq_g=
et_fd(q->outq), PA_IO_EVENT_INPUT, asyncmsgq_cb, q));
+}
+
+void pa_thread_mq_done(pa_thread_mq *q) {
+    pa_assert(q);
+
+    q->mainloop->io_free(q->io_event);
+    q->io_event =3D NULL;
+
+    pa_asyncmsgq_after_poll(q->outq);
+    pa_asyncmsgq_free(q->inq);
+    pa_asyncmsgq_free(q->outq);
+    q->inq =3D q->outq =3D NULL;
+    =

+    q->mainloop =3D NULL;
+}
+
+static void init_tls(void) {
+    tls =3D pa_tls_new(NULL);
+}
+
+void pa_thread_mq_install(pa_thread_mq *q) {
+    pa_assert(q);
+
+    pa_run_once(&once, init_tls);
+    pa_tls_set(tls, q);
+}
+
+pa_thread_mq *pa_thread_mq_get(void) {
+    pa_thread_mq *q;
+
+    pa_run_once(&once, init_tls);
+    pa_assert_se(q =3D pa_tls_get(tls));
+    return q;
+}
+

Added: branches/lennart/src/pulsecore/thread-mq.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
thread-mq.h?rev=3D1622&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/thread-mq.h (added)
+++ branches/lennart/src/pulsecore/thread-mq.h Sat Aug 11 00:01:17 2007
@@ -1,0 +1,49 @@
+#ifndef foopulsethreadmqhfoo
+#define foopulsethreadmqhfoo
+
+/* $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 <pulse/mainloop-api.h>
+#include <pulsecore/asyncmsgq.h>
+
+/* Two way communication between a thread and a mainloop. Before the
+ * thread is started a pa_pthread_mq should be initialized and than
+ * attached to the thread using pa_thread_mq_install(). */
+
+typedef struct pa_thread_mq {
+    pa_mainloop_api *mainloop;
+    pa_asyncmsgq *inq, *outq;
+    pa_io_event *io_event;
+} pa_thread_mq;
+
+void pa_thread_mq_init(pa_thread_mq *q, pa_mainloop_api *mainloop);
+void pa_thread_mq_done(pa_thread_mq *q);
+
+/* Install the specified pa_thread_mq object for the current thread */
+void pa_thread_mq_install(pa_thread_mq *q);
+
+/* Return the pa_thread_mq object that is set for the current thread */
+pa_thread_mq *pa_thread_mq_get(void);
+
+#endif

Propchange: branches/lennart/src/pulsecore/thread-mq.h
---------------------------------------------------------------------------=
---
    svn:keywords =3D pulsecore/thread-mq.c




More information about the pulseaudio-commits mailing list