[5510] | 1 | //mainloop-threaded.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5961] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014 |
---|
[5510] | 5 | * The code (may) include prototypes and comments (and maybe |
---|
| 6 | * other code fragements) from libpulse*. They are mostly copyrighted by: |
---|
| 7 | * Lennart Poettering <poettering@users.sourceforge.net> and |
---|
| 8 | * Pierre Ossman <drzeus@drzeus.cx> |
---|
| 9 | * |
---|
| 10 | * This file is part of libroarpulse a part of RoarAudio, |
---|
| 11 | * a cross-platform sound system for both, home and professional use. |
---|
| 12 | * See README for details. |
---|
| 13 | * |
---|
| 14 | * This file is free software; you can redistribute it and/or modify |
---|
| 15 | * it under the terms of the GNU General Public License version 3 |
---|
| 16 | * as published by the Free Software Foundation. |
---|
| 17 | * |
---|
| 18 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 21 | * GNU General Public License for more details. |
---|
| 22 | * |
---|
| 23 | * You should have received a copy of the GNU General Public License |
---|
| 24 | * along with this software; see the file COPYING. If not, write to |
---|
| 25 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 26 | * |
---|
| 27 | * NOTE for everyone want's to change something and send patches: |
---|
| 28 | * read README and HACKING! There a addition information on |
---|
| 29 | * the license of this document you need to read before you send |
---|
| 30 | * any patches. |
---|
| 31 | * |
---|
| 32 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 33 | * or libpulse*: |
---|
| 34 | * The libs libroaresd, libroararts and libroarpulse link this libroar |
---|
| 35 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 36 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | #include <libroarpulse/libroarpulse.h> |
---|
| 40 | |
---|
| 41 | struct pa_threaded_mainloop { |
---|
| 42 | pa_mainloop_api api; |
---|
| 43 | int started; |
---|
| 44 | size_t lockc; |
---|
| 45 | int retval; |
---|
| 46 | }; |
---|
| 47 | |
---|
| 48 | static void __quit(pa_mainloop_api*a, int retval) { |
---|
| 49 | pa_threaded_mainloop * m = a->userdata; |
---|
| 50 | m->retval = retval; |
---|
| 51 | pa_threaded_mainloop_stop(m); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | static const pa_mainloop_api __api = { |
---|
| 55 | .quit = __quit |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | pa_threaded_mainloop *pa_threaded_mainloop_new(void) { |
---|
| 59 | pa_threaded_mainloop * ret = roar_mm_malloc(sizeof(pa_threaded_mainloop)); |
---|
| 60 | if ( ret == NULL ) { |
---|
| 61 | // handle errors here. |
---|
| 62 | return NULL; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | memset(ret, 0, sizeof(pa_threaded_mainloop)); |
---|
| 66 | |
---|
| 67 | ret->api = __api; |
---|
| 68 | ret->api.userdata = ret; |
---|
| 69 | |
---|
| 70 | return ret; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void pa_threaded_mainloop_free(pa_threaded_mainloop* m) { |
---|
| 74 | if ( m == NULL ) |
---|
| 75 | return; |
---|
| 76 | |
---|
| 77 | roar_mm_free(m); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | int pa_threaded_mainloop_start(pa_threaded_mainloop *m) { |
---|
| 81 | m->started = 1; |
---|
| 82 | return 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | void pa_threaded_mainloop_stop(pa_threaded_mainloop *m) { |
---|
| 86 | m->started = 1; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void pa_threaded_mainloop_lock(pa_threaded_mainloop *m) { |
---|
| 90 | m->lockc++; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void pa_threaded_mainloop_unlock(pa_threaded_mainloop *m) { |
---|
| 94 | if ( m->lockc != 0 ) |
---|
| 95 | m->lockc--; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void pa_threaded_mainloop_wait(pa_threaded_mainloop *m); |
---|
| 99 | void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept); |
---|
| 100 | void pa_threaded_mainloop_accept(pa_threaded_mainloop *m); |
---|
| 101 | |
---|
| 102 | int pa_threaded_mainloop_get_retval(pa_threaded_mainloop *m) { |
---|
| 103 | return m->retval; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m) { |
---|
| 107 | return &(m->api); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | int pa_threaded_mainloop_in_thread(pa_threaded_mainloop *m) { |
---|
| 111 | (void)m; |
---|
| 112 | return 0; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | //ll |
---|