mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
move pa_queue to an implementation based on pa_flist
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1619 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
ac49cc2029
commit
d4cb042a56
3 changed files with 107 additions and 21 deletions
|
|
@ -223,7 +223,8 @@ noinst_PROGRAMS = \
|
||||||
thread-test \
|
thread-test \
|
||||||
flist-test \
|
flist-test \
|
||||||
asyncq-test \
|
asyncq-test \
|
||||||
asyncmsgq-test
|
asyncmsgq-test \
|
||||||
|
queue-test
|
||||||
|
|
||||||
if HAVE_SIGXCPU
|
if HAVE_SIGXCPU
|
||||||
noinst_PROGRAMS += \
|
noinst_PROGRAMS += \
|
||||||
|
|
@ -293,6 +294,11 @@ asyncmsgq_test_CFLAGS = $(AM_CFLAGS)
|
||||||
asyncmsgq_test_LDADD = $(AM_LDADD) libpulsecore.la
|
asyncmsgq_test_LDADD = $(AM_LDADD) libpulsecore.la
|
||||||
asyncmsgq_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
|
asyncmsgq_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
|
||||||
|
|
||||||
|
queue_test_SOURCES = tests/queue-test.c
|
||||||
|
queue_test_CFLAGS = $(AM_CFLAGS)
|
||||||
|
queue_test_LDADD = $(AM_LDADD) libpulsecore.la
|
||||||
|
queue_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
|
||||||
|
|
||||||
mcalign_test_SOURCES = tests/mcalign-test.c
|
mcalign_test_SOURCES = tests/mcalign-test.c
|
||||||
mcalign_test_CFLAGS = $(AM_CFLAGS)
|
mcalign_test_CFLAGS = $(AM_CFLAGS)
|
||||||
mcalign_test_LDADD = $(AM_LDADD) $(WINSOCK_LIBS) libpulsecore.la
|
mcalign_test_LDADD = $(AM_LDADD) $(WINSOCK_LIBS) libpulsecore.la
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,16 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <pulse/xmalloc.h>
|
#include <pulse/xmalloc.h>
|
||||||
|
#include <pulsecore/macro.h>
|
||||||
|
#include <pulsecore/flist.h>
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
PA_STATIC_FLIST_DECLARE(entries, 0, pa_xfree);
|
||||||
|
|
||||||
struct queue_entry {
|
struct queue_entry {
|
||||||
struct queue_entry *next;
|
struct queue_entry *next;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
@ -44,25 +47,24 @@ struct pa_queue {
|
||||||
|
|
||||||
pa_queue* pa_queue_new(void) {
|
pa_queue* pa_queue_new(void) {
|
||||||
pa_queue *q = pa_xnew(pa_queue, 1);
|
pa_queue *q = pa_xnew(pa_queue, 1);
|
||||||
|
|
||||||
q->front = q->back = NULL;
|
q->front = q->back = NULL;
|
||||||
q->length = 0;
|
q->length = 0;
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_queue_free(pa_queue* q, void (*destroy)(void *p, void *userdata), void *userdata) {
|
void pa_queue_free(pa_queue* q, void (*destroy)(void *p, void *userdata), void *userdata) {
|
||||||
struct queue_entry *e;
|
void *data;
|
||||||
assert(q);
|
pa_assert(q);
|
||||||
|
|
||||||
e = q->front;
|
|
||||||
while (e) {
|
|
||||||
struct queue_entry *n = e->next;
|
|
||||||
|
|
||||||
|
while ((data = pa_queue_pop(q)))
|
||||||
if (destroy)
|
if (destroy)
|
||||||
destroy(e->data, userdata);
|
destroy(data, userdata);
|
||||||
|
|
||||||
pa_xfree(e);
|
pa_assert(!q->front);
|
||||||
e = n;
|
pa_assert(!q->back);
|
||||||
}
|
pa_assert(q->length == 0);
|
||||||
|
|
||||||
pa_xfree(q);
|
pa_xfree(q);
|
||||||
}
|
}
|
||||||
|
|
@ -70,14 +72,17 @@ void pa_queue_free(pa_queue* q, void (*destroy)(void *p, void *userdata), void *
|
||||||
void pa_queue_push(pa_queue *q, void *p) {
|
void pa_queue_push(pa_queue *q, void *p) {
|
||||||
struct queue_entry *e;
|
struct queue_entry *e;
|
||||||
|
|
||||||
e = pa_xnew(struct queue_entry, 1);
|
if (!(e = pa_flist_pop(PA_STATIC_FLIST_GET(entries))))
|
||||||
|
e = pa_xnew(struct queue_entry, 1);
|
||||||
|
|
||||||
e->data = p;
|
e->data = p;
|
||||||
e->next = NULL;
|
e->next = NULL;
|
||||||
|
|
||||||
if (q->back)
|
if (q->back) {
|
||||||
|
pa_assert(q->front);
|
||||||
q->back->next = e;
|
q->back->next = e;
|
||||||
else {
|
} else {
|
||||||
assert(!q->front);
|
pa_assert(!q->front);
|
||||||
q->front = e;
|
q->front = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,17 +93,22 @@ void pa_queue_push(pa_queue *q, void *p) {
|
||||||
void* pa_queue_pop(pa_queue *q) {
|
void* pa_queue_pop(pa_queue *q) {
|
||||||
void *p;
|
void *p;
|
||||||
struct queue_entry *e;
|
struct queue_entry *e;
|
||||||
assert(q);
|
pa_assert(q);
|
||||||
|
|
||||||
if (!(e = q->front))
|
if (!(e = q->front))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
q->front = e->next;
|
q->front = e->next;
|
||||||
if (q->back == e)
|
|
||||||
|
if (q->back == e) {
|
||||||
|
pa_assert(!e->next);
|
||||||
q->back = NULL;
|
q->back = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
p = e->data;
|
p = e->data;
|
||||||
pa_xfree(e);
|
|
||||||
|
if (pa_flist_push(PA_STATIC_FLIST_GET(entries), e) < 0)
|
||||||
|
pa_xfree(e);
|
||||||
|
|
||||||
q->length--;
|
q->length--;
|
||||||
|
|
||||||
|
|
@ -106,6 +116,7 @@ void* pa_queue_pop(pa_queue *q) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_queue_is_empty(pa_queue *q) {
|
int pa_queue_is_empty(pa_queue *q) {
|
||||||
assert(q);
|
pa_assert(q);
|
||||||
|
|
||||||
return q->length == 0;
|
return q->length == 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
69
src/tests/queue-test.c
Normal file
69
src/tests/queue-test.c
Normal file
|
|
@ -0,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 = 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue