1 #ifndef foopulseasyncqhfoo
2 #define foopulseasyncqhfoo
5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <sys/types.h>
26 #include <pulse/def.h>
27 #include <pulsecore/macro.h>
29 /* A simple, asynchronous, lock-free (if requested also wait-free)
30 * queue. Not multiple-reader/multiple-writer safe. If that is
31 * required both sides can be protected by a mutex each. --- Which is
32 * not a bad thing in most cases, since this queue is intended for
33 * communication between a normal thread and a single real-time
34 * thread. Only the real-time side needs to be lock-free/wait-free.
36 * If the queue is full and another entry shall be pushed, or when the
37 * queue is empty and another entry shall be popped and the "wait"
38 * argument is non-zero, the queue will block on a UNIX FIFO object --
39 * that will probably require locking on the kernel side -- which
40 * however is probably not problematic, because we do it only on
41 * starvation or overload in which case we have to block anyway. */
43 typedef struct pa_asyncq pa_asyncq;
45 pa_asyncq* pa_asyncq_new(unsigned size);
46 void pa_asyncq_free(pa_asyncq* q, pa_free_cb_t free_cb);
48 void* pa_asyncq_pop(pa_asyncq *q, pa_bool_t wait);
49 int pa_asyncq_push(pa_asyncq *q, void *p, pa_bool_t wait);
51 /* Similar to pa_asyncq_push(), but if the queue is full, postpone it
52 * locally and delay until pa_asyncq_before_poll_post() */
53 void pa_asyncq_post(pa_asyncq*l, void *p);
55 /* For the reading side */
56 int pa_asyncq_read_fd(pa_asyncq *q);
57 int pa_asyncq_read_before_poll(pa_asyncq *a);
58 void pa_asyncq_read_after_poll(pa_asyncq *a);
60 /* For the writing side */
61 int pa_asyncq_write_fd(pa_asyncq *q);
62 void pa_asyncq_write_before_poll(pa_asyncq *a);
63 void pa_asyncq_write_after_poll(pa_asyncq *a);