2 This file is part of PulseAudio.
4 Copyright 2004-2008 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/xmalloc.h>
29 #include <pulsecore/macro.h>
30 #include <pulsecore/flist.h>
34 PA_STATIC_FLIST_DECLARE(entries
, 0, pa_xfree
);
37 struct queue_entry
*next
;
42 struct queue_entry
*front
, *back
;
46 pa_queue
* pa_queue_new(void) {
47 pa_queue
*q
= pa_xnew(pa_queue
, 1);
49 q
->front
= q
->back
= NULL
;
55 void pa_queue_free(pa_queue
* q
, pa_free2_cb_t free_func
, void *userdata
) {
59 while ((data
= pa_queue_pop(q
)))
61 free_func(data
, userdata
);
65 pa_assert(q
->length
== 0);
70 void pa_queue_push(pa_queue
*q
, void *p
) {
71 struct queue_entry
*e
;
76 if (!(e
= pa_flist_pop(PA_STATIC_FLIST_GET(entries
))))
77 e
= pa_xnew(struct queue_entry
, 1);
94 void* pa_queue_pop(pa_queue
*q
) {
96 struct queue_entry
*e
;
112 if (pa_flist_push(PA_STATIC_FLIST_GET(entries
), e
) < 0)
120 int pa_queue_isempty(pa_queue
*q
) {
123 return q
->length
== 0;