[pulseaudio-commits] r1619 - in /branches/lennart/src: ./ Makefile.am pulsecore/queue.c tests/queue-test.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Aug 10 09:47:40 PDT 2007


Author: lennart
Date: Fri Aug 10 18:47:39 2007
New Revision: 1619

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1619&root=3Dpulseaudio&vi=
ew=3Drev
Log:
move pa_queue to an implementation based on pa_flist

Added:
    branches/lennart/src/tests/queue-test.c   (with props)
Modified:
    branches/lennart/src/   (props changed)
    branches/lennart/src/Makefile.am
    branches/lennart/src/pulsecore/queue.c

Propchange: branches/lennart/src/
---------------------------------------------------------------------------=
---
--- svn:ignore (original)
+++ svn:ignore Fri Aug 10 18:47:39 2007
@@ -1,3 +1,4 @@
+queue-test
 asyncmsgq-test
 asyncq-test
 flist-test

Modified: branches/lennart/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/Makefile.a=
m?rev=3D1619&root=3Dpulseaudio&r1=3D1618&r2=3D1619&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 Fri Aug 10 18:47:39 2007
@@ -223,7 +223,8 @@
 		thread-test \
 		flist-test \
 		asyncq-test \
-		asyncmsgq-test
+		asyncmsgq-test \
+		queue-test
 =

 if HAVE_SIGXCPU
 noinst_PROGRAMS +=3D \
@@ -292,6 +293,11 @@
 asyncmsgq_test_CFLAGS =3D $(AM_CFLAGS)
 asyncmsgq_test_LDADD =3D $(AM_LDADD) libpulsecore.la
 asyncmsgq_test_LDFLAGS =3D $(AM_LDFLAGS) $(BINLDFLAGS)
+
+queue_test_SOURCES =3D tests/queue-test.c
+queue_test_CFLAGS =3D $(AM_CFLAGS)
+queue_test_LDADD =3D $(AM_LDADD) libpulsecore.la
+queue_test_LDFLAGS =3D $(AM_LDFLAGS) $(BINLDFLAGS)
 =

 mcalign_test_SOURCES =3D tests/mcalign-test.c
 mcalign_test_CFLAGS =3D $(AM_CFLAGS)

Modified: branches/lennart/src/pulsecore/queue.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
queue.c?rev=3D1619&root=3Dpulseaudio&r1=3D1618&r2=3D1619&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/pulsecore/queue.c (original)
+++ branches/lennart/src/pulsecore/queue.c Fri Aug 10 18:47:39 2007
@@ -25,12 +25,15 @@
 #include <config.h>
 #endif
 =

-#include <assert.h>
 #include <stdlib.h>
 =

 #include <pulse/xmalloc.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/flist.h>
 =

 #include "queue.h"
+
+PA_STATIC_FLIST_DECLARE(entries, 0, pa_xfree);
 =

 struct queue_entry {
     struct queue_entry *next;
@@ -44,40 +47,42 @@
 =

 pa_queue* pa_queue_new(void) {
     pa_queue *q =3D pa_xnew(pa_queue, 1);
+    =

     q->front =3D q->back =3D NULL;
     q->length =3D 0;
+    =

     return q;
 }
 =

 void pa_queue_free(pa_queue* q, void (*destroy)(void *p, void *userdata), =
void *userdata) {
-    struct queue_entry *e;
-    assert(q);
+    void *data;
+    pa_assert(q);
 =

-    e =3D q->front;
-    while (e) {
-        struct queue_entry *n =3D e->next;
+    while ((data =3D pa_queue_pop(q)))
+        if (destroy)
+            destroy(data, userdata);
 =

-        if (destroy)
-            destroy(e->data, userdata);
-
-        pa_xfree(e);
-        e =3D n;
-    }
-
+    pa_assert(!q->front);
+    pa_assert(!q->back);
+    pa_assert(q->length =3D=3D 0);
+    =

     pa_xfree(q);
 }
 =

 void pa_queue_push(pa_queue *q, void *p) {
     struct queue_entry *e;
 =

-    e =3D pa_xnew(struct queue_entry, 1);
+    if (!(e =3D pa_flist_pop(PA_STATIC_FLIST_GET(entries))))
+        e =3D pa_xnew(struct queue_entry, 1);
+    =

     e->data =3D p;
     e->next =3D NULL;
 =

-    if (q->back)
+    if (q->back) {
+        pa_assert(q->front);
         q->back->next =3D e;
-    else {
-        assert(!q->front);
+    } else {
+        pa_assert(!q->front);
         q->front =3D e;
     }
 =

@@ -88,24 +93,30 @@
 void* pa_queue_pop(pa_queue *q) {
     void *p;
     struct queue_entry *e;
-    assert(q);
+    pa_assert(q);
 =

     if (!(e =3D q->front))
         return NULL;
 =

     q->front =3D e->next;
-    if (q->back =3D=3D e)
+
+    if (q->back =3D=3D e) {
+        pa_assert(!e->next);
         q->back =3D NULL;
+    }
 =

     p =3D e->data;
-    pa_xfree(e);
 =

+    if (pa_flist_push(PA_STATIC_FLIST_GET(entries), e) < 0)
+        pa_xfree(e);
+    =

     q->length--;
 =

     return p;
 }
 =

 int pa_queue_is_empty(pa_queue *q) {
-    assert(q);
+    pa_assert(q);
+    =

     return q->length =3D=3D 0;
 }

Added: branches/lennart/src/tests/queue-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/tests/queu=
e-test.c?rev=3D1619&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/tests/queue-test.c (added)
+++ branches/lennart/src/tests/queue-test.c Fri Aug 10 18:47:39 2007
@@ -1,0 +1,69 @@
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  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 <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <pulse/util.h>
+#include <pulse/xmalloc.h>
+#include <pulsecore/queue.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+int main(int argc, char *argv[]) {
+    pa_queue *q;
+
+    pa_assert_se(q =3D pa_queue_new());
+
+    pa_assert(pa_queue_is_empty(q));
+    =

+    pa_queue_push(q, (void*) "eins");
+    pa_log("%s\n", (char*) pa_queue_pop(q));
+
+    pa_assert(pa_queue_is_empty(q));
+    =

+    pa_queue_push(q, (void*) "zwei");
+    pa_queue_push(q, (void*) "drei");
+    pa_queue_push(q, (void*) "vier");
+
+    pa_log("%s\n", (char*) pa_queue_pop(q));
+    pa_log("%s\n", (char*) pa_queue_pop(q));
+
+    pa_queue_push(q, (void*) "fuenf");
+
+    pa_log("%s\n", (char*) pa_queue_pop(q));
+    pa_log("%s\n", (char*) pa_queue_pop(q));
+
+    pa_assert(pa_queue_is_empty(q));
+
+    pa_queue_push(q, (void*) "sechs");
+    pa_queue_push(q, (void*) "sieben");
+    =

+    pa_queue_free(q, NULL, NULL);
+
+    return 0;
+}

Propchange: branches/lennart/src/tests/queue-test.c
---------------------------------------------------------------------------=
---
    svn:keywords =3D Id




More information about the pulseaudio-commits mailing list