1 #ifndef foopulseasyncqhfoo 2 #define foopulseasyncqhfoo 3 4 /*** 5 This file is part of PulseAudio. 6 7 Copyright 2004-2006 Lennart Poettering 8 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. 13 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. 18 19 You should have received a copy of the GNU Lesser General Public 20 License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 21 ***/ 22 23 #include <sys/types.h> 24 #include <pulse/def.h> 25 #include <pulsecore/macro.h> 26 27 /* A simple, asynchronous, lock-free (if requested also wait-free) 28 * queue. Not multiple-reader/multiple-writer safe. If that is 29 * required both sides can be protected by a mutex each. --- Which is 30 * not a bad thing in most cases, since this queue is intended for 31 * communication between a normal thread and a single real-time 32 * thread. Only the real-time side needs to be lock-free/wait-free. 33 * 34 * If the queue is full and another entry shall be pushed, or when the 35 * queue is empty and another entry shall be popped and the "wait" 36 * argument is non-zero, the queue will block on a UNIX FIFO object -- 37 * that will probably require locking on the kernel side -- which 38 * however is probably not problematic, because we do it only on 39 * starvation or overload in which case we have to block anyway. */ 40 41 typedef struct pa_asyncq pa_asyncq; 42 43 pa_asyncq* pa_asyncq_new(unsigned size); 44 void pa_asyncq_free(pa_asyncq* q, pa_free_cb_t free_cb); 45 46 void* pa_asyncq_pop(pa_asyncq *q, bool wait); 47 int pa_asyncq_push(pa_asyncq *q, void *p, bool wait); 48 49 /* Similar to pa_asyncq_push(), but if the queue is full, postpone the 50 * appending of the item locally and delay until 51 * pa_asyncq_before_poll_post() is called. */ 52 void pa_asyncq_post(pa_asyncq*l, void *p); 53 54 /* For the reading side */ 55 int pa_asyncq_read_fd(pa_asyncq *q); 56 int pa_asyncq_read_before_poll(pa_asyncq *a); 57 void pa_asyncq_read_after_poll(pa_asyncq *a); 58 59 /* For the writing side */ 60 int pa_asyncq_write_fd(pa_asyncq *q); 61 void pa_asyncq_write_before_poll(pa_asyncq *a); 62 void pa_asyncq_write_after_poll(pa_asyncq *a); 63 64 #endif 65